[cfe-commits] r126485 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaCXX/nested-name-spec-locations.cpp
Douglas Gregor
dgregor at apple.com
Fri Feb 25 07:54:31 PST 2011
Author: dgregor
Date: Fri Feb 25 09:54:31 2011
New Revision: 126485
URL: http://llvm.org/viewvc/llvm-project?rev=126485&view=rev
Log:
Maintain nested-name-specifier source-location information through
instantiation of using declarations (all three forms).
Added:
cfe/trunk/test/SemaCXX/nested-name-spec-locations.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=126485&r1=126484&r2=126485&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Feb 25 09:54:31 2011
@@ -1661,11 +1661,10 @@
// template struct t<int>;
// Here, in using s1::f1, s1 refers to t<T>::s1;
// we need to substitute for t<int>::s1.
- NestedNameSpecifier *NNS
- = SemaRef.SubstNestedNameSpecifier(D->getQualifier(),
- D->getQualifierRange(),
- TemplateArgs);
- if (!NNS)
+ NestedNameSpecifierLoc QualifierLoc
+ = SemaRef.SubstNestedNameSpecifierLoc(D->getQualifierLoc(),
+ TemplateArgs);
+ if (!QualifierLoc)
return 0;
// The name info is non-dependent, so no transformation
@@ -1680,18 +1679,14 @@
LookupResult Prev(SemaRef, NameInfo, Sema::LookupUsingDeclName,
Sema::ForRedeclaration);
- CXXScopeSpec SS;
- if (NNS == D->getQualifier())
- SS.Adopt(D->getQualifierLoc());
- else
- SS.MakeTrivial(SemaRef.Context, NNS, D->getQualifierRange());
-
UsingDecl *NewUD = UsingDecl::Create(SemaRef.Context, Owner,
D->getUsingLocation(),
- SS.getWithLocInContext(SemaRef.Context),
+ QualifierLoc,
NameInfo,
D->isTypeName());
+ CXXScopeSpec SS;
+ SS.Adopt(QualifierLoc);
if (CheckRedeclaration) {
Prev.setHideTags(false);
SemaRef.LookupQualifiedName(Prev, Owner);
@@ -1750,14 +1745,14 @@
Decl * TemplateDeclInstantiator
::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
- NestedNameSpecifier *NNS =
- SemaRef.SubstNestedNameSpecifier(D->getQualifier(), D->getQualifierRange(),
- TemplateArgs);
- if (!NNS)
+ NestedNameSpecifierLoc QualifierLoc
+ = SemaRef.SubstNestedNameSpecifierLoc(D->getQualifierLoc(),
+ TemplateArgs);
+ if (!QualifierLoc)
return 0;
CXXScopeSpec SS;
- SS.MakeTrivial(SemaRef.Context, NNS, D->getQualifierRange());
+ SS.Adopt(QualifierLoc);
// Since NameInfo refers to a typename, it cannot be a C++ special name.
// Hence, no tranformation is required for it.
@@ -1775,14 +1770,13 @@
Decl * TemplateDeclInstantiator
::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
- NestedNameSpecifier *NNS =
- SemaRef.SubstNestedNameSpecifier(D->getQualifier(), D->getQualifierRange(),
- TemplateArgs);
- if (!NNS)
+ NestedNameSpecifierLoc QualifierLoc
+ = SemaRef.SubstNestedNameSpecifierLoc(D->getQualifierLoc(), TemplateArgs);
+ if (!QualifierLoc)
return 0;
-
+
CXXScopeSpec SS;
- SS.MakeTrivial(SemaRef.Context, NNS, D->getQualifierRange());
+ SS.Adopt(QualifierLoc);
DeclarationNameInfo NameInfo
= SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs);
Added: cfe/trunk/test/SemaCXX/nested-name-spec-locations.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nested-name-spec-locations.cpp?rev=126485&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/nested-name-spec-locations.cpp (added)
+++ cfe/trunk/test/SemaCXX/nested-name-spec-locations.cpp Fri Feb 25 09:54:31 2011
@@ -0,0 +1,42 @@
+// RUN: %clang-cc1 -fsyntax-only -verify %s
+
+// Note: the formatting in this test case is intentionally funny, with
+// nested-name-specifiers stretched out vertically so that we can
+// match up diagnostics per-line and still verify that we're getting
+// good source-location information.
+
+namespace outer {
+ namespace inner {
+ template<typename T>
+ struct X0 {
+ };
+ }
+}
+
+template<typename T>
+struct add_reference {
+ typedef T& type;
+};
+
+namespace outer_alias = outer;
+
+template<typename T>
+struct UnresolvedUsingValueDeclTester {
+ using outer::inner::X0<
+ typename add_reference<T>::type
+ * // expected-error{{declared as a pointer to a reference of type}}
+ >::value;
+};
+
+UnresolvedUsingValueDeclTester<int> UnresolvedUsingValueDeclCheck; // expected-note{{in instantiation of template class}}
+
+template<typename T>
+struct UnresolvedUsingTypenameDeclTester {
+ using outer::inner::X0<
+ typename add_reference<T>::type
+ * // expected-error{{declared as a pointer to a reference of type}}
+ >::value;
+};
+
+UnresolvedUsingTypenameDeclTester<int> UnresolvedUsingTypenameDeclCheck; // expected-note{{in instantiation of template class}}
+
More information about the cfe-commits
mailing list