[llvm-bugs] [Bug 49676] New: Clang does not detect narrowing in aggregate (array) initialization
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Mar 22 03:56:21 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=49676
Bug ID: 49676
Summary: Clang does not detect narrowing in aggregate (array)
initialization
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: dangelog at gmail.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
Testcase:
extern long double l;
struct S {
S(int) {}
};
S s[] = { l };
This is supposed to be ill-formed because of narrowing. Clang does not reject
the code, nor it warns (as it usually does for narrowing).
The relevant rule is in [dcl.init.aggr]:
https://eel.is/c++draft/dcl.init.aggr#4.2.sentence-2
> Otherwise, the element is copy-initialized from the corresponding initializer-clause or is initialized with the brace-or-equal-initializer of the corresponding designated-initializer-clause.
> If that initializer is of the form assignment-expression or = assignment-expression and a narrowing conversion ([dcl.init.list]) is required to convert the expression, the program is ill-formed.
That rule has been changed in C++20 with designated initializers, but the same
one was also there for C++17 and before, e.g.
https://timsong-cpp.github.io/cppwp/n4659/dcl.init.aggr#3
For comparison, GCC accepts with no warnings, but MSVC warns about narrowing.
For reference, I've reported this very same bug against GCC here
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99625 .
--
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/20210322/45f2670e/attachment.html>
More information about the llvm-bugs
mailing list