[llvm-bugs] [Bug 26852] New: false negative for -Wconstant-logical-operand in C++ mode, not in C

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Mar 5 08:35:33 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=26852

            Bug ID: 26852
           Summary: false negative for -Wconstant-logical-operand in C++
                    mode, not in C
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ed0.88.prez at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Consider this snippet code:

$ cat enum_constant_operand.cpp
int bar();

typedef enum
{
    X = 1,
    Y = 2,
    Z = 4,
} val_t;

int foo()
{
    int val = bar();
    return (val == X || Y || Z);
}
EOF

If it's compiled in C mode, it reports:

$ clang++ -x c enum_constant_operand.cpp -fsyntax-only
enum_constant_operand.cpp:13:19: warning: use of logical '||' with constant
      operand [-Wconstant-logical-operand]
        return (val == X || Y || Z);
                         ^  ~
enum_constant_operand.cpp:13:19: note: use '|' for a bitwise operation
        return (val == X || Y || Z);
                         ^~
                         |
enum_constant_operand.cpp:13:24: warning: use of logical '||' with constant
      operand [-Wconstant-logical-operand]
        return (val == X || Y || Z);
                              ^  ~
enum_constant_operand.cpp:13:24: note: use '|' for a bitwise operation
        return (val == X || Y || Z);
                              ^~
                              |
2 warnings generated.
$

If it's compiled in C++, it won't report anything:
$ clang++ enum_constant_operand.cpp -fsyntax-only
$

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160305/629ad57b/attachment.html>


More information about the llvm-bugs mailing list