From: Douglas Gregor Date: Wed, 2 Sep 2009 13:05:45 +0000 (+0000) Subject: When parsing typename specifiers (with either the identifier or X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6946baf3542dcb1ed0d98d0fdda451d1c39a49c2;p=clang When parsing typename specifiers (with either the identifier or simple-template-id form), check whether the scope specifier is computable as a declaration context rather than checking whether it is dependent, so that we properly cope with members of the current instantiation. Improve testing for typename specifiers that terminate in a simpe-template-id. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80783 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index bf506415ac..c6ea357fbd 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -530,7 +530,7 @@ const TemplateSpecializationType * Type::getAsTemplateSpecializationType() const { // There is no sugar for class template specialization types, so // just return the canonical type pointer if it is the right class. - return dyn_cast(CanonicalType); + return this->getAs(); } bool Type::isIntegerType() const { diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 3985c1c0e0..8566789ccd 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -1137,9 +1137,7 @@ Sema::ActOnDependentTemplateName(SourceLocation TemplateKWLoc, NestedNameSpecifier *Qualifier = static_cast(SS.getScopeRep()); - // FIXME: member of the current instantiation - - if (!Qualifier->isDependent()) { + if (computeDeclContext(SS, false)) { // C++0x [temp.names]p5: // If a name prefixed by the keyword template is not the name of // a template, the program is ill-formed. [Note: the keyword @@ -3010,10 +3008,16 @@ Sema::ActOnTypenameType(SourceLocation TypenameLoc, const CXXScopeSpec &SS, = T->getAsTemplateSpecializationType(); assert(TemplateId && "Expected a template specialization type"); - if (NNS->isDependent()) - return Context.getTypenameType(NNS, TemplateId).getAsOpaquePtr(); - - return Context.getQualifiedNameType(NNS, T).getAsOpaquePtr(); + if (computeDeclContext(SS, false)) { + // If we can compute a declaration context, then the "typename" + // keyword was superfluous. Just build a QualifiedNameType to keep + // track of the nested-name-specifier. + + // FIXME: Note that the QualifiedNameType had the "typename" keyword! + return Context.getQualifiedNameType(NNS, T).getAsOpaquePtr(); + } + + return Context.getTypenameType(NNS, TemplateId).getAsOpaquePtr(); } /// \brief Build the type that describes a C++ typename specifier, diff --git a/test/SemaTemplate/typename-specifier-4.cpp b/test/SemaTemplate/typename-specifier-4.cpp new file mode 100644 index 0000000000..2b1517e40c --- /dev/null +++ b/test/SemaTemplate/typename-specifier-4.cpp @@ -0,0 +1,56 @@ +// RUN: clang-cc -fsyntax-only -verify %s +template +struct is_same { + static const bool value = false; +}; + +template +struct is_same { + static const bool value = true; +}; + +template +struct metafun_apply2 { + typedef typename MetaFun::template apply inner; + typedef typename inner::type type; +}; + +template struct pair; + +struct make_pair { + template + struct apply { + typedef pair type; + }; +}; + +int a0[is_same::type, + pair >::value? 1 : -1]; +int a1[is_same< + typename make_pair::template apply, + make_pair::apply + >::value? 1 : -1]; + +template +struct swap_and_apply2 { + template + struct apply { + typedef typename MetaFun::template apply new_metafun; + typedef typename new_metafun::type type; + }; +}; + +int a2[is_same::apply::type, + pair >::value? 1 : -1]; + +template +struct X0 { + template + struct Inner; + + void f0(X0::Inner); // expected-note{{here}} + void f0(typename X0::Inner); // expected-error{{redecl}} + + void f1(X0::Inner); // expected-note{{here}} + void f1(typename X0::template Inner); // expected-error{{redecl}} +};