[cfe-commits] r147620 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/temp/temp.decls/temp.variadic/p4.cpp test/SemaCXX/dependent-auto.cpp
Eli Friedman
eli.friedman at gmail.com
Thu Jan 5 14:34:09 PST 2012
Author: efriedma
Date: Thu Jan 5 16:34:08 2012
New Revision: 147620
URL: http://llvm.org/viewvc/llvm-project?rev=147620&view=rev
Log:
Tweak the fix to PR8977: an empty expression-list represents value initialization, not default initialization. Fixes PR11712.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
cfe/trunk/test/SemaCXX/dependent-auto.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=147620&r1=147619&r2=147620&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jan 5 16:34:08 2012
@@ -1172,6 +1172,8 @@
"declaration of variable %0 with type %1 requires an initializer">;
def err_auto_new_requires_ctor_arg : Error<
"new expression for type %0 requires a constructor argument">;
+def err_auto_var_init_no_expression : Error<
+ "initializer for variable %0 with type %1 is empty">;
def err_auto_var_init_multiple_expressions : Error<
"initializer for variable %0 with type %1 contains multiple expressions">;
def err_auto_new_ctor_multiple_expressions : Error<
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=147620&r1=147619&r2=147620&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Jan 5 16:34:08 2012
@@ -8898,8 +8898,6 @@
MultiExprArg Exprs,
SourceLocation RParenLoc,
bool TypeMayContainAuto) {
- assert(Exprs.size() != 0 && Exprs.get() && "missing expressions");
-
// If there is no declaration, there was an error parsing it. Just ignore
// the initializer.
if (RealDecl == 0)
@@ -8912,9 +8910,18 @@
return;
}
- // C++0x [decl.spec.auto]p6. Deduce the type which 'auto' stands in for.
+ // C++0x [dcl.spec.auto]p6. Deduce the type which 'auto' stands in for.
if (TypeMayContainAuto && VDecl->getType()->getContainedAutoType()) {
- // FIXME: n3225 doesn't actually seem to indicate this is ill-formed
+ if (Exprs.size() == 0) {
+ // It isn't possible to write this directly, but it is possible to
+ // end up in this situation with "auto x(some_pack...);"
+ Diag(LParenLoc, diag::err_auto_var_init_no_expression)
+ << VDecl->getDeclName() << VDecl->getType()
+ << VDecl->getSourceRange();
+ RealDecl->setInvalidDecl();
+ return;
+ }
+
if (Exprs.size() > 1) {
Diag(Exprs.get()[1]->getSourceRange().getBegin(),
diag::err_auto_var_init_multiple_expressions)
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=147620&r1=147619&r2=147620&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Jan 5 16:34:08 2012
@@ -393,16 +393,15 @@
if (!SemaRef.InstantiateInitializer(D->getInit(), TemplateArgs, LParenLoc,
InitArgs, RParenLoc)) {
bool TypeMayContainAuto = true;
- // Attach the initializer to the declaration, if we have one.
- if (InitArgs.size() == 0)
- SemaRef.ActOnUninitializedDecl(Var, TypeMayContainAuto);
- else if (D->hasCXXDirectInitializer()) {
+ if (D->hasCXXDirectInitializer()) {
// Add the direct initializer to the declaration.
SemaRef.AddCXXDirectInitializerToDecl(Var,
LParenLoc,
move_arg(InitArgs),
RParenLoc,
TypeMayContainAuto);
+ } else if (InitArgs.size() == 0) {
+ SemaRef.ActOnUninitializedDecl(Var, TypeMayContainAuto);
} else {
assert(InitArgs.size() == 1);
Expr *Init = InitArgs.take()[0];
Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p4.cpp?rev=147620&r1=147619&r2=147620&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p4.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/p4.cpp Thu Jan 5 16:34:08 2012
@@ -37,7 +37,8 @@
namespace PR8977 {
struct A { };
template<typename T, typename... Args> void f(Args... args) {
- T t(args...);
+ // An empty expression-list performs value initialization.
+ constexpr T t(args...);
};
template void f<A>();
Modified: cfe/trunk/test/SemaCXX/dependent-auto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/dependent-auto.cpp?rev=147620&r1=147619&r2=147620&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/dependent-auto.cpp (original)
+++ cfe/trunk/test/SemaCXX/dependent-auto.cpp Thu Jan 5 16:34:08 2012
@@ -8,7 +8,7 @@
template<typename ...T>
void f(T ...t) {
- auto x(t...); // expected-error {{requires an initializer}} expected-error {{contains multiple expressions}}
+ auto x(t...); // expected-error {{is empty}} expected-error {{contains multiple expressions}}
only<int> check = x;
}
More information about the cfe-commits
mailing list