http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53792
--- Comment #2 from vincenzo Innocente <vincenzo.innocente at cern dot ch> 2012-06-28 11:08:38 UTC --- On 28 Jun, 2012, at 11:34 AM, rguenth at gcc dot gnu.org wrote: > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53792 > > Richard Guenther <rguenth at gcc dot gnu.org> changed: > > What |Removed |Added > ---------------------------------------------------------------------------- > Status|UNCONFIRMED |NEW > Last reconfirmed| |2012-06-28 > Ever Confirmed|0 |1 > > --- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-06-28 > 09:34:20 UTC --- > Does the C++ standard require getIndex to be evaluated to a constant in getV? No, a constexpr function can be used as a "normal" function. For instance if getV was not inlined the correct behaviour is what we observe > Or is 'constexpr' only telling you that it is required ina context where > evaluation to a constant is required (and thus arguments to a constexpr > function are constrained)? I would say yes (a constant needs to be evaluated using a constexpr function. see page 148-150 (166-168 of my pdf) of the standard (7.1.5 point 3 and following) > My point is that the compiler does not identify that "getIndex" is a constant expression in the context of foo nor in context of the following foo2 that indeed produce (as it should) identical code to foo int foo2() { const double a = v[getIndex("a",theMap)]; const double b = v[getIndex("b",theMap)]; if (a==b) return 1; return 0; }