[PATCH] D64087: [clang] Correct source locations for instantiations of out-of-line defaulted special member functions. (PR25683)
Tom Honermann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 2 10:17:16 PDT 2019
tahonermann created this revision.
tahonermann added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Fixes PR25683 (https://bugs.llvm.org/show_bug.cgi?id=25683)
This change completes adjustments of source locations for FunctionDecl
definitions corresponding to function template instantiations. Prior
changes made back in 2011 (
"Fixed implicit instantiations source range."
https://github.com/llvm/llvm-project/commit/12dcbf3eaa6d2c8b9ee814ddb8bf23bef644bfaf
) updated the "inner start location" when instantiating a definition,
but for out-of-line definitions of defaulted special member functions
(functions without defined bodies), this resulted in the
"inner start location" matching the location of the out-of-line
defaulted definition, but left the end location matching the end of
the in-class declaration. With this change, the declaration location,
"inner start location", and end location are now all adjusted to match
the FunctionDecl for the template pattern.
Repository:
rC Clang
https://reviews.llvm.org/D64087
Files:
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaCXX/member-init.cpp
clang/test/SemaTemplate/virtual-member-functions.cpp
Index: clang/test/SemaTemplate/virtual-member-functions.cpp
===================================================================
--- clang/test/SemaTemplate/virtual-member-functions.cpp
+++ clang/test/SemaTemplate/virtual-member-functions.cpp
@@ -7,10 +7,10 @@
namespace PR5557 {
template <class T> struct A {
- A(); // expected-note{{instantiation}}
+ A();
virtual int a(T x);
};
-template<class T> A<T>::A() {}
+template<class T> A<T>::A() {} // expected-note{{instantiation}}
template<class T> int A<T>::a(T x) {
return *x; // expected-error{{requires pointer operand}}
@@ -33,10 +33,10 @@
namespace PR5557_dtor {
template <class T> struct A {
A(); // Don't have an implicit constructor.
- ~A(); // expected-note{{instantiation}}
+ ~A();
virtual int a(T x);
};
-template<class T> A<T>::~A() {}
+template<class T> A<T>::~A() {} // expected-note{{instantiation}}
template<class T> int A<T>::a(T x) {
return *x; // expected-error{{requires pointer operand}}
Index: clang/test/SemaCXX/member-init.cpp
===================================================================
--- clang/test/SemaCXX/member-init.cpp
+++ clang/test/SemaCXX/member-init.cpp
@@ -164,11 +164,11 @@
namespace explicit_instantiation {
template<typename T> struct X {
- X(); // expected-note {{in instantiation of default member initializer 'explicit_instantiation::X<float>::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<int>; // ok
-template<typename T> X<T>::X() {}
+template<typename T> X<T>::X() {} // expected-note {{in instantiation of default member initializer 'explicit_instantiation::X<float>::n' requested here}}
template struct X<float>; // expected-note {{in instantiation of member function 'explicit_instantiation::X<float>::X' requested here}}
}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4234,8 +4234,10 @@
// unimported module.
Function->setVisibleDespiteOwningModule();
- // Copy the inner loc start from the pattern.
+ // Copy source locations from the pattern.
+ Function->setLocation(PatternDecl->getLocation());
Function->setInnerLocStart(PatternDecl->getInnerLocStart());
+ Function->setRangeEnd(PatternDecl->getEndLoc());
EnterExpressionEvaluationContext EvalContext(
*this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64087.207587.patch
Type: text/x-patch
Size: 2597 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190702/55c27c3f/attachment.bin>
More information about the cfe-commits
mailing list