https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83504
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> --- Template specializations are handled correctly. But the test case doesn't actually show a bug in how overloads are handled -- I forgot that GCC eliminates the calls to the non-const function because it sees its definition. My bad. With that fixed like below the test case shows that GCC behaves correctly even for overloads. $ cat u.C && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout u.C int i; int __attribute__ ((noclone, noinline)) f (int) { return i; } int __attribute__ ((const)) f (); void g (void) { i = 0; int j = f (0); i = 1; if (j == f (0)) __builtin_abort (); } ... g () { int j; int _1; <bb 2> [local count: 1073741825]: i = 0; j_4 = f (0); i = 1; _1 = f (0); if (_1 == j_4) goto <bb 3>; [0.00%] else goto <bb 4>; [99.96%] <bb 3> [count: 0]: __builtin_abort (); <bb 4> [local count: 1073312327]: return; }