From 486c529987375143c1ca508a76c751cb07c56324 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 14 Feb 2018 16:31:26 +0000 Subject: [PATCH] [C++ PATCH]: instantiation via vtable marking https://gcc.gnu.org/ml/gcc-patches/2018-02/msg00850.html gcc/cp/ * decl2.c (mark_vtable_entries): Set input_location to decl's. (c_parse_final_cleanups): Restore input_location after emitting vtables. gcc/testsuite/ * g++.dg/template/instantiate5.C: Adjust required-from loc. From-SVN: r257665 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl2.c | 8 ++++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/template/instantiate5.C | 9 +++++++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4955bf9e1a0..673d6e32453 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-02-14 Nathan Sidwell + + * decl2.c (mark_vtable_entries): Set input_location to decl's. + (c_parse_final_cleanups): Restore input_location after emitting + vtables. + 2018-02-14 Paolo Carlini * cp-tree.h (do_auto_deduction (tree, tree, tree)): Remove. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 2da6f9023c5..d2693ce458b 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1825,6 +1825,11 @@ mark_vtable_entries (tree decl) function, so we emit the thunks there instead. */ if (DECL_THUNK_P (fn)) use_thunk (fn, /*emit_p=*/0); + /* Set the location, as marking the function could cause + instantiation. We do not need to preserve the incoming + location, as we're called from c_parse_final_cleanups, which + takes care of that. */ + input_location = DECL_SOURCE_LOCATION (fn); mark_used (fn); } } @@ -4727,6 +4732,9 @@ c_parse_final_cleanups (void) reconsider = true; keyed_classes->unordered_remove (i); } + /* The input_location may have been changed during marking of + vtable entries. */ + input_location = locus_at_end_of_parsing; /* Write out needed type info variables. We have to be careful looping through unemitted decls, because emit_tinfo_decl may diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0f08e15e2ac..4fb11dfa011 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-02-14 Nathan Sidwell + + * g++.dg/template/instantiate5.C: Adjust required-from loc. + 2018-02-14 Will Schmidt * gcc.target/powerpc/altivec-consts.c: Update compile stanzas. diff --git a/gcc/testsuite/g++.dg/template/instantiate5.C b/gcc/testsuite/g++.dg/template/instantiate5.C index 896313d14d5..d64092eb1a8 100644 --- a/gcc/testsuite/g++.dg/template/instantiate5.C +++ b/gcc/testsuite/g++.dg/template/instantiate5.C @@ -18,7 +18,12 @@ struct B template struct C { - virtual void bar() const { T::foo(); } // { dg-error "no matching function" } + virtual void bar() const // { dg-message "required" } + { + T::foo(); // { dg-error "no matching function" } + } }; -C c; // { dg-message "required" } +C c; + +int k; -- 2.30.2