diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-01-13 02:14:39 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-01-13 02:14:39 +0000 |
commit | f037541d5c7dcf3553cf26e4b047be869980c23a (patch) | |
tree | 42a279788b28adbd1cf9b0ef10cdb7af116f134d | |
parent | 2f4d88f4418afafbd0b22ce0f79cdead6f3a6f99 (diff) |
Don't crash while trying to diagnose a function declared at block scope with an
incomplete return type.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148088 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/SemaFixItUtils.cpp | 6 | ||||
-rw-r--r-- | test/SemaCXX/decl-expr-ambiguity.cpp | 4 |
3 files changed, 10 insertions, 3 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 4dcf1db2cf..20309ee51c 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4945,7 +4945,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, // Empty parens mean value-initialization, and no parens mean default // initialization. These are equivalent if the default constructor is // user-provided, or if zero-initialization is a no-op. - if (RD && (RD->isEmpty() || RD->hasUserProvidedDefaultConstructor())) + if (RD && RD->hasDefinition() && + (RD->isEmpty() || RD->hasUserProvidedDefaultConstructor())) Diag(C.Loc, diag::note_empty_parens_default_ctor) << FixItHint::CreateRemoval(ParenRange); else if (const char *Init = getFixItZeroInitializerForType(T)) diff --git a/lib/Sema/SemaFixItUtils.cpp b/lib/Sema/SemaFixItUtils.cpp index 1f17a9e83e..0f7530b415 100644 --- a/lib/Sema/SemaFixItUtils.cpp +++ b/lib/Sema/SemaFixItUtils.cpp @@ -180,9 +180,11 @@ const char *Sema::getFixItZeroInitializerForType(QualType T) const { if (T->isScalarType()) return " = 0"; const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); - if (LangOpts.CPlusPlus0x && RD && !RD->hasUserProvidedDefaultConstructor()) + if (!RD || !RD->hasDefinition()) + return 0; + if (LangOpts.CPlusPlus0x && !RD->hasUserProvidedDefaultConstructor()) return "{}"; - if (T->isAggregateType()) + if (RD->isAggregate()) return " = {}"; return 0; } diff --git a/test/SemaCXX/decl-expr-ambiguity.cpp b/test/SemaCXX/decl-expr-ambiguity.cpp index f6dbe2f339..6f4d08cc68 100644 --- a/test/SemaCXX/decl-expr-ambiguity.cpp +++ b/test/SemaCXX/decl-expr-ambiguity.cpp @@ -50,10 +50,14 @@ struct RAII { void func(); namespace N { + struct S; + void emptyParens() { RAII raii(); // expected-warning {{function declaration}} expected-note {{remove parentheses to declare a variable}} int a, b, c, d, e, // expected-note {{change this ',' to a ';' to call 'func'}} func(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} + + S s(); // expected-warning {{function declaration}} } } |