summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEnea Zaffanella <zaffanella@cs.unipr.it>2013-01-11 14:34:39 +0000
committerEnea Zaffanella <zaffanella@cs.unipr.it>2013-01-11 14:34:39 +0000
commit29e1c4b03efefe4e3942757a4ad4710fe9ac284c (patch)
treee3e9adc54a7fd5d047f48042d6c9ea354923709c
parentfd8c4b1321165c9ac6de235ceb74b6bcb4e43296 (diff)
downloadbcm5719-llvm-29e1c4b03efefe4e3942757a4ad4710fe9ac284c.tar.gz
bcm5719-llvm-29e1c4b03efefe4e3942757a4ad4710fe9ac284c.zip
Fixed an assertion failure triggered by invalid code.
Set invalid type of declarator after emitting error diagnostics, so that it won't be later considered when instantiating the template. Added test5_inst in test/SemaCXX/condition.cpp for non-regression. llvm-svn: 172201
-rw-r--r--clang/lib/Sema/SemaType.cpp4
-rw-r--r--clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8.cpp6
-rw-r--r--clang/test/SemaCXX/alias-template.cpp4
-rw-r--r--clang/test/SemaCXX/condition.cpp11
4 files changed, 17 insertions, 8 deletions
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 1bdd7c3b398..60db55aff33 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1996,6 +1996,7 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
SemaRef.Diag(OwnedTagDecl->getLocation(),
diag::err_type_defined_in_alias_template)
<< SemaRef.Context.getTypeDeclType(OwnedTagDecl);
+ D.setInvalidType(true);
break;
case Declarator::TypeNameContext:
case Declarator::TemplateParamContext:
@@ -2006,6 +2007,7 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
SemaRef.Diag(OwnedTagDecl->getLocation(),
diag::err_type_defined_in_type_specifier)
<< SemaRef.Context.getTypeDeclType(OwnedTagDecl);
+ D.setInvalidType(true);
break;
case Declarator::PrototypeContext:
case Declarator::ObjCParameterContext:
@@ -2016,6 +2018,7 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
SemaRef.Diag(OwnedTagDecl->getLocation(),
diag::err_type_defined_in_param_type)
<< SemaRef.Context.getTypeDeclType(OwnedTagDecl);
+ D.setInvalidType(true);
break;
case Declarator::ConditionContext:
// C++ 6.4p2:
@@ -2023,6 +2026,7 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
// a new class or enumeration.
SemaRef.Diag(OwnedTagDecl->getLocation(),
diag::err_type_defined_in_condition);
+ D.setInvalidType(true);
break;
}
}
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8.cpp
index 34a8c854a6b..ec1ccbf5de5 100644
--- a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8.cpp
@@ -1,10 +1,8 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
struct A { };
-A::A (enum { e1 }) {} // expected-error{{can not be defined in a parameter}} \
-// expected-error{{out-of-line definition}}
-void A::f(enum { e2 }) {} // expected-error{{can not be defined in a parameter}} \
-// expected-error{{out-of-line definition}}
+A::A (enum { e1 }) {} // expected-error{{can not be defined in a parameter}}
+void A::f(enum { e2 }) {} // expected-error{{can not be defined in a parameter}}
enum { e3 } A::g() { } // expected-error{{can not be defined in the result type}} \
// expected-error{{out-of-line definition}}
diff --git a/clang/test/SemaCXX/alias-template.cpp b/clang/test/SemaCXX/alias-template.cpp
index 4bf79f851e0..db9c82afd59 100644
--- a/clang/test/SemaCXX/alias-template.cpp
+++ b/clang/test/SemaCXX/alias-template.cpp
@@ -105,9 +105,7 @@ namespace TagName {
template<typename Z> using S = struct { int n; }; // expected-error {{can not be defined}}
template<typename Z> using T = class { int n; }; // expected-error {{can not be defined}}
template<typename Z> using U = enum { a, b, c }; // expected-error {{can not be defined}}
- template<typename Z> using V = struct V { int n; }; // expected-error {{redefinition of 'V' as different kind of symbol}} \
- expected-error {{'TagName::V' can not be defined in a type alias template}} \
- expected-note {{previous definition is here}}
+ template<typename Z> using V = struct V { int n; }; // expected-error {{'TagName::V' can not be defined in a type alias template}}
}
namespace StdExample {
diff --git a/clang/test/SemaCXX/condition.cpp b/clang/test/SemaCXX/condition.cpp
index ec5eb17b08f..d8058811948 100644
--- a/clang/test/SemaCXX/condition.cpp
+++ b/clang/test/SemaCXX/condition.cpp
@@ -19,7 +19,7 @@ void test() {
while (struct NewS *x=0) ;
while (struct S {} *x=0) ; // expected-error {{types may not be defined in conditions}}
while (struct {} *x=0) ; // expected-error {{types may not be defined in conditions}}
- switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{cannot initialize}} \
+ switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} \
// expected-warning{{enumeration value 'E' not handled in switch}} expected-warning {{switch statement has empty body}} \
// expected-note{{put the semicolon on a separate line}}
@@ -58,3 +58,12 @@ void test3() {
void test4(bool (&x)(void)) {
while (x);
}
+
+template <class>
+void test5() {
+ if (struct S {}* p = 0) // expected-error {{types may not be defined in conditions}}
+ ;
+}
+void test5_inst() {
+ test5<int>();
+}
OpenPOWER on IntegriCloud