containing designators. The C++20 wording doesn't actually say what
happens in this case, but treating this as a non-deduced context seems
like the most natural behavior.
(We might want to consider deducing through array designators as an
extension in the future, but will need to be careful to deduce the array
bound properly if we do so. That's not permitted herein.)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370555
91177308-0d34-0410-b5e6-
96231b3b80d8
return Sema::TDK_Success;
}
+ // Resolving a core issue: a braced-init-list containing any designators is
+ // a non-deduced context.
+ for (Expr *E : ILE->inits())
+ if (isa<DesignatedInitExpr>(E))
+ return Sema::TDK_Success;
+
// Deduction only needs to be done for dependent types.
if (ElTy->isDependentType()) {
for (Expr *E : ILE->inits()) {
if (!Type.getType().getNonReferenceType()->getAs<AutoType>())
return DAR_Failed;
+ // Resolving a core issue: a braced-init-list containing any designators is
+ // a non-deduced context.
+ for (Expr *E : InitList->inits())
+ if (isa<DesignatedInitExpr>(E))
+ return DAR_Failed;
+
SourceRange DeducedFromInitRange;
for (unsigned i = 0, e = InitList->getNumInits(); i < e; ++i) {
Expr *Init = InitList->getInit(i);
typedef const _E* iterator;
typedef const _E* const_iterator;
- initializer_list() : __begin_(nullptr), __size_(0) {}
+ constexpr initializer_list() : __begin_(nullptr), __size_(0) {}
- size_t size() const {return __size_;}
+ constexpr size_t size() const {return __size_;}
const _E* begin() const {return __begin_;}
const _E* end() const {return __begin_ + __size_;}
};
struct Y { using T = std::initializer_list<Y>(*)(); operator T(); };
auto (*y)() = { Y() }; // expected-error {{from initializer list}}
}
+
+namespace designated_init {
+ constexpr auto a = {.a = 1, .b = 2}; // expected-error {{cannot deduce}}
+ constexpr auto b = {[0] = 1, [4] = 2}; // expected-error {{cannot deduce}} expected-warning {{C99}}
+ constexpr auto c = {1, [4] = 2}; // expected-error {{cannot deduce}} expected-warning 2{{C99}} expected-note {{here}}
+ constexpr auto d = {1, [0] = 2}; // expected-error {{cannot deduce}} expected-warning 2{{C99}} expected-note {{here}}
+
+ // If we ever start accepting the above, these assertions should pass.
+ static_assert(c.size() == 5, "");
+ static_assert(d.size() == 1, "");
+}
#endif
}
}
+
+namespace designators {
+ template<typename T, int N> constexpr int f(T (&&)[N]) { return N; } // expected-note 2{{couldn't infer template argument 'T'}}
+ static_assert(f({1, 2, [20] = 3}) == 3, ""); // expected-error {{no matching function}} expected-warning 2{{C99}} expected-note {{}}
+
+ static_assert(f({.a = 1, .b = 2}) == 3, ""); // expected-error {{no matching function}}
+}