Skip to content

False positives with -Wconstant-logical-operand in template code #10583

@rjmccall

Description

@rjmccall
Bugzilla Link 10211
Resolution DUPLICATE
Resolved on Nov 07, 2018 00:22
Version trunk
OS All
CC @DougGregor

Extended Description

-Wconstant-logical-operand warns about code where the constant argument was instantiated from a template. This is idiomatically acceptable code. It comes up a lot in e.g. Eigen:
http://eigen.tuxfamily.org/index.php?title=Main_Page
Anyone verifying this should probably do a test compile with some Eigen files, e.g. 2.0.15's test/geometry.cpp [note: clang -I.. -D test_geometry], but here's a short reduction of a few cases we should get:

template class A {
unsigned count() { return 0; }

bool test1() { return (count() && int(T::SomeBit)); }

enum {
  SomeBit = T::SomeBit
};
bool test2() { return (count() && int(SomeBit)); }

};
struct B { enum { SomeBit = true }; };
template class A;

The warning doesn't trigger here without the function-style casts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++duplicateResolved as duplicate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions