[llvm-bugs] [Bug 24771] New: Missed diagnostic in narrowing conversion from unscoped enum to floating

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Sep 10 08:21:19 PDT 2015


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

            Bug ID: 24771
           Summary: Missed diagnostic in narrowing conversion from
                    unscoped enum to floating
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: andrey.vul at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

A narrowing conversion from an unscoped enumeration to a floating-point type
fails to emit a -Wc++11-narrowing diagnostic.

If we try the same, -Wc++11-narrowing works as expected.


### SOURCE:
$ cat narrowing.cc
int x0 = 5;
double y0 = { x0 }; // (1)
enum { z1 = 5 } x1 = z1;
double y1 = { x1 }; // (2)


### COMPILER INVOCATION AND OUTPUT:
$ clang++ -std=c++11 -c -Werror=c++11-narrowing narrowing.cc

narrowing.cc:2:15: error: non-constant-expression cannot be narrowed from type
      'int' to 'double' in initializer list [-Wc++11-narrowing]
double y0 = { x0 };
              ^~
### EXPECTED OUTPUT:
narrowing.cc:2:15: error: non-constant-expression cannot be narrowed from type
      'int' to 'double' in initializer list [-Wc++11-narrowing]
double y0 = { x0 };
              ^~
narrowing.cc:4:15: error: non-constant-expression cannot be narrowed from type
      '<anonymous enum>' to 'double' in initializer list [-Wc++11-narrowing]
double y1 = { x1 };
              ^~

NOTE: the second diagnostic was synthesized from gcc -Werror=narrowing

### COMPILER VERSION INFO:
clang version 3.8.0 (trunk 246556)
Target: powerpc64le-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/powerpc64le-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/powerpc64le-linux-gnu/4.8.2
Found candidate GCC installation: /usr/lib/gcc/powerpc64le-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/powerpc64le-linux-gnu/4.9.1
Selected GCC installation: /usr/lib/gcc/powerpc64le-linux-gnu/4.8
Candidate multilib: .;@m64
Selected multilib: .;@m64

-- 
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/20150910/955feeb8/attachment.html>


More information about the llvm-bugs mailing list