-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Open
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"waiting-for-wg21Blocked on C++ Standards CommitteeBlocked on C++ Standards Committee
Description
struct C {
union {
int a;
const char* p;
};
};
struct D {
int a = 1;
const char* p = "bad";
};
int f(C);
int f(D);
int i = f({.a = 2, .p = "ok"});
Clang should either reject as ambiguous, or remove f(C)
from the overload set under https://wg21.link/dcl.init.aggr#4.1.sentence-2 and call f(D)
with a D{.a = 2, .p = "ok"}
(the standard is not particularly clear on this; this came up discussing CWG 2169). It should not call f(D)
with a D{}
(i.e. D{.a = 1, .p = "bad"}
), but that's what it does.
Also, it comes up with a comedy warning:
warning: ISO C++ requires field designators to be specified in declaration order; field 'p' will be initialized after field '' [-Wreorder-init-list]
<source>:13:20: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
int i = f({.a = 2, .p = "ok"});
^~~~~~~~~
<source>:13:17: note: previous initialization is here
int i = f({.a = 2, .p = "ok"});
^
If you remove the declaration f(C);
, it DTRT.
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"waiting-for-wg21Blocked on C++ Standards CommitteeBlocked on C++ Standards Committee