Index: gcc/testsuite/g++.dg/gcov/gcov-5.C =================================================================== --- gcc/testsuite/g++.dg/gcov/gcov-5.C (revision 0) +++ gcc/testsuite/g++.dg/gcov/gcov-5.C (revision 0) @@ -0,0 +1,50 @@ +/* Check that execution counts for template functions + are reported correctly by gcov. */ + +#include +#include + +/* { dg-options "-fprofile-arcs -ftest-coverage -fno-inline" } */ +/* { dg-do run { target native } } */ + +class A { + int count; + public: + A(int c) { count = c; } + void func(void) { printf("func\n"); } + bool done(void) { + return (count == 0) ? true : (count-- != 0); + } + void run(void) { abort(); } +}; + +//typedef A T; +template +void WithoutBrace(T *a) { + while (!a->done()) + a->run(); /* count(#####) */ +} /* count(1) */ + +template +void WithBrace(T *a) +{ + while (!a->done()) + { + a->run(); /* count(#####) */ + } +} /* count(1) */ + +A *func(A *a) +{ + WithoutBrace(a); + WithBrace(a); + return a; +} + +int main() { + A a(0); + func(&a); + return 0; +} + +/* { dg-final { run-gcov gcov-5.C } } */ Index: gcc/cp/pt.c =================================================================== --- gcc/cp/pt.c (revision 127246) +++ gcc/cp/pt.c (working copy) @@ -14438,6 +14438,12 @@ instantiate_decl (tree d, int defer_ok, tf_warning_or_error, tmpl, /*integral_constant_expression_p=*/false); + /* Make sure the current input_location + is set correctly to the end of the function + - this makes finish_function to set + function_end_locus of this specialization correctly. */ + input_location = DECL_STRUCT_FUNCTION (code_pattern)->function_end_locus; + /* We don't need the local specializations any more. */ htab_delete (local_specializations); local_specializations = saved_local_specializations;