[cfe-commits] r130298 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaTemplateInstantiate.cpp test/CXX/class/class.mem/p2.cpp test/SemaCXX/PR9460.cpp test/SemaCXX/PR9461.cpp
John McCall
rjmccall at apple.com
Tue Apr 26 23:46:31 PDT 2011
Author: rjmccall
Date: Wed Apr 27 01:46:31 2011
New Revision: 130298
URL: http://llvm.org/viewvc/llvm-project?rev=130298&view=rev
Log:
Diagnose attempts to implicitly instantiate a template before it is
fully defined. Somehow this escaped notice for a very long time.
Added:
cfe/trunk/test/CXX/class/class.mem/p2.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/test/SemaCXX/PR9460.cpp
cfe/trunk/test/SemaCXX/PR9461.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=130298&r1=130297&r2=130298&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Apr 27 01:46:31 2011
@@ -1863,6 +1863,9 @@
def note_template_recursion_depth : Note<
"use -ftemplate-depth-N to increase recursive template instantiation depth">;
+def err_template_instantiate_within_definition : Error<
+ "%select{implicit|explicit}0 instantiation of template %1 within its"
+ " own definition">;
def err_template_instantiate_undefined : Error<
"%select{implicit|explicit}0 instantiation of undefined template %1">;
def err_implicit_instantiate_member_undefined : Error<
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=130298&r1=130297&r2=130298&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Wed Apr 27 01:46:31 2011
@@ -1650,9 +1650,18 @@
CXXRecordDecl *PatternDef
= cast_or_null<CXXRecordDecl>(Pattern->getDefinition());
- if (!PatternDef) {
- if (!Complain) {
+ if (!PatternDef || PatternDef->isBeingDefined()) {
+ if (!Complain || (PatternDef && PatternDef->isInvalidDecl())) {
// Say nothing
+ } else if (PatternDef) {
+ assert(PatternDef->isBeingDefined());
+ Diag(PointOfInstantiation,
+ diag::err_template_instantiate_within_definition)
+ << (TSK != TSK_ImplicitInstantiation)
+ << Context.getTypeDeclType(Instantiation);
+ // Not much point in noting the template declaration here, since
+ // we're lexically inside it.
+ Instantiation->setInvalidDecl();
} else if (Pattern == Instantiation->getInstantiatedFromMemberClass()) {
Diag(PointOfInstantiation,
diag::err_implicit_instantiate_member_undefined)
Added: cfe/trunk/test/CXX/class/class.mem/p2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.mem/p2.cpp?rev=130298&view=auto
==============================================================================
--- cfe/trunk/test/CXX/class/class.mem/p2.cpp (added)
+++ cfe/trunk/test/CXX/class/class.mem/p2.cpp Wed Apr 27 01:46:31 2011
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// C++11 [class.mem]p2:
+// A class is considered a completely-defined object type (or
+// complete type) at the closing } of the class-specifier. Within
+// the class member-specification, the class is regarded as complete
+// within function bodies, default arguments,
+// exception-specifications, and brace-or-equal-initializers for
+// non-static data members (including such things in nested classes).
+// Otherwise it is regarded as incomplete within its own class
+// member-specification.
+
+namespace test0 {
+ struct A { // expected-note {{definition of 'test0::A' is not complete until the closing '}'}}
+ A x; // expected-error {{field has incomplete type 'test0::A'}}
+ };
+}
+
+namespace test1 {
+ template <class T> struct A {
+ A<int> x; // expected-error {{implicit instantiation of template 'test1::A<int>' within its own definition}}
+ };
+}
+
+namespace test2 {
+ template <class T> struct A;
+ template <> struct A<int> {};
+ template <class T> struct A {
+ A<int> x;
+ };
+}
Modified: cfe/trunk/test/SemaCXX/PR9460.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR9460.cpp?rev=130298&r1=130297&r2=130298&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/PR9460.cpp (original)
+++ cfe/trunk/test/SemaCXX/PR9460.cpp Wed Apr 27 01:46:31 2011
@@ -8,11 +8,11 @@
basic_string(aT*);
};
-struct runtime_error{
-runtime_error(
+struct runtime_error{ // expected-note {{candidate constructor}}
+ runtime_error( // expected-note {{candidate constructor}}
basic_string<char> struct{ // expected-error {{cannot combine with previous 'type-name' declaration specifier}}
a(){ // expected-error {{requires a type specifier}}
-runtime_error(0);
+ runtime_error(0); // expected-error {{no matching conversion}}
}
}
);
Modified: cfe/trunk/test/SemaCXX/PR9461.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR9461.cpp?rev=130298&r1=130297&r2=130298&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/PR9461.cpp (original)
+++ cfe/trunk/test/SemaCXX/PR9461.cpp Wed Apr 27 01:46:31 2011
@@ -26,7 +26,7 @@
:us(_S_construct)
{string a;}
-struct runtime_error{runtime_error(string);};
+struct runtime_error{runtime_error(string);}; // expected-note 2 {{candidate constructor}}
struct system_error:runtime_error{ // expected-note {{to match}} expected-note {{specified here}}
-system_error():time_error("" // expected-error 4 {{expected}} expected-error {{initializer}} expected-note {{to match}}
+system_error():time_error("" // expected-error 4 {{expected}} expected-error {{initializer}} expected-note {{to match}} expected-error {{no matching constructor}}
More information about the cfe-commits
mailing list