[PATCH] D38216: [C++17] Fix class template argument deduction for default constructors without an initializer
Zhihao Yuan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 23 21:35:02 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328409: [C++17] Fix class template argument deduction for default constructors without… (authored by lichray, committed by ).
Repository:
rC Clang
https://reviews.llvm.org/D38216
Files:
lib/Sema/SemaDecl.cpp
test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp
test/Parser/cxx1z-class-template-argument-deduction.cpp
Index: test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp
===================================================================
--- test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp
+++ test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp
@@ -5,8 +5,7 @@
A(int) -> A<char>;
static constexpr inline const volatile A a = {}; // ok, specifiers are permitted
-// FIXME: There isn't really a good reason to reject this.
-A b; // expected-error {{requires an initializer}}
+A b;
A c [[]] {};
A d = {}, e = {};
@@ -16,3 +15,5 @@
static A a; // expected-error {{requires an initializer}}
};
extern A x; // expected-error {{requires an initializer}}
+static A y;
+
Index: test/Parser/cxx1z-class-template-argument-deduction.cpp
===================================================================
--- test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -137,7 +137,6 @@
(void)A{n};
(void)new A(n);
(void)new A{n};
- // FIXME: We should diagnose the lack of an initializer here.
(void)new A;
}
}
@@ -150,7 +149,7 @@
auto k() -> A; // expected-error{{requires template arguments}}
- A a; // expected-error {{declaration of variable 'a' with deduced type 'A' requires an initializer}}
+ A a;
A b = 0;
const A c = 0;
A (parens) = 0; // expected-error {{cannot use parentheses when declaring variable with deduced class template specialization type}}
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -10396,12 +10396,22 @@
// C++11 [dcl.spec.auto]p3
if (!Init) {
assert(VDecl && "no init for init capture deduction?");
- Diag(VDecl->getLocation(), diag::err_auto_var_requires_init)
- << VDecl->getDeclName() << Type;
- return QualType();
+
+ // Except for class argument deduction, and then for an initializing
+ // declaration only, i.e. no static at class scope or extern.
+ if (!isa<DeducedTemplateSpecializationType>(Deduced) ||
+ VDecl->hasExternalStorage() ||
+ VDecl->isStaticDataMember()) {
+ Diag(VDecl->getLocation(), diag::err_auto_var_requires_init)
+ << VDecl->getDeclName() << Type;
+ return QualType();
+ }
}
- ArrayRef<Expr*> DeduceInits = Init;
+ ArrayRef<Expr*> DeduceInits;
+ if (Init)
+ DeduceInits = Init;
+
if (DirectInit) {
if (auto *PL = dyn_cast_or_null<ParenListExpr>(Init))
DeduceInits = PL->exprs();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38216.139697.patch
Type: text/x-patch
Size: 2568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180324/d04da656/attachment.bin>
More information about the cfe-commits
mailing list