diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -291,6 +291,12 @@ pointers on win32. (`#62594 `_) +- Fixed some cases where the source location for an instantiated specialization + of a function template or a member function of a class template was assigned + the location of a non-defining declaration rather than the location of the + definition the specialization was instantiated from. + (`#26057 `_`) + Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed an import failure of recursive friend class template. diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -4990,8 +4990,10 @@ // unimported module. Function->setVisibleDespiteOwningModule(); - // Copy the inner loc start from the pattern. + // Copy the source locations from the pattern. + Function->setLocation(PatternDecl->getLocation()); Function->setInnerLocStart(PatternDecl->getInnerLocStart()); + Function->setRangeEnd(PatternDecl->getEndLoc()); EnterExpressionEvaluationContext EvalContext( *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); diff --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp --- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp +++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp @@ -209,10 +209,10 @@ namespace p2085_2 { template struct S6 { - // expected-error@+2{{found 'const int &'}} - // expected-error@+1{{found 'const float &'}} bool operator==(T const &) const; }; +// expected-error@+2{{found 'const int &'}} +// expected-error@+1{{found 'const float &'}} template bool S6::operator==(T const &) const = default; template struct S6; // expected-note{{S6::operator==' requested}} diff --git a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp --- a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp +++ b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp @@ -102,14 +102,14 @@ namespace forward_declare_consteval{ template -constexpr int f(T t); // expected-note {{'f' defined here}} +constexpr int f(T t); auto a = &f; auto b = &f; // expected-error {{immediate function 'f' used before it is defined}} \ // expected-note {{in instantiation of function template specialization}} template -constexpr int f(T t) { +constexpr int f(T t) { // expected-note {{'f' defined here}} return id(t); // expected-note {{'f' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}} } } diff --git a/clang/test/SemaCXX/member-init.cpp b/clang/test/SemaCXX/member-init.cpp --- a/clang/test/SemaCXX/member-init.cpp +++ b/clang/test/SemaCXX/member-init.cpp @@ -164,11 +164,11 @@ namespace explicit_instantiation { template struct X { - X(); // expected-note {{in instantiation of default member initializer 'explicit_instantiation::X::n' requested here}} + X(); int n = T::error; // expected-error {{type 'float' cannot be used prior to '::' because it has no members}} }; template struct X; // ok -template X::X() {} +template X::X() {} // expected-note {{in instantiation of default member initializer 'explicit_instantiation::X::n' requested here}} template struct X; // expected-note {{in instantiation of member function 'explicit_instantiation::X::X' requested here}} } @@ -197,3 +197,15 @@ } template void foo(int); } + +namespace GH26057 { +template +struct S { + S(); + int dm = T::error; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}} +}; +template +S::S() = default; // expected-note {{in instantiation of default member initializer 'GH26057::S::dm' requested here}} \ + // expected-note {{in evaluation of exception specification for 'GH26057::S::S' needed here}} +template struct S; // expected-note {{in instantiation of member function 'GH26057::S::S' requested here}} +} diff --git a/clang/test/SemaTemplate/virtual-member-functions.cpp b/clang/test/SemaTemplate/virtual-member-functions.cpp --- a/clang/test/SemaTemplate/virtual-member-functions.cpp +++ b/clang/test/SemaTemplate/virtual-member-functions.cpp @@ -7,10 +7,10 @@ namespace PR5557 { template struct A { - A(); // expected-note{{instantiation}} + A(); virtual int a(T x); }; -template A::A() {} +template A::A() {} // expected-note{{instantiation}} template int A::a(T x) { return *x; // expected-error{{requires pointer operand}} @@ -33,10 +33,10 @@ namespace PR5557_dtor { template struct A { A(); // Don't have an implicit constructor. - ~A(); // expected-note{{instantiation}} + ~A(); virtual int a(T x); }; -template A::~A() {} +template A::~A() {} // expected-note{{instantiation}} template int A::a(T x) { return *x; // expected-error{{requires pointer operand}}