[Bug c++/57248] string parameter to constexpr functions
paolo.carlini at oracle dot com
gcc-bugzilla@gcc.gnu.org
Fri Sep 5 10:51:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57248
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |paolo.carlini at oracle dot com
--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
It would be nice if Daniel could have another look to this, because his reduced
testcase in Comment #3 doesn't work anymore as a reproducer, is simply accepted
by eg, the released 4.9.0.
Also, I note that all the compilers I have at hand reject the original testcase
and also, eg:
constexpr bool strmatch(const char *s1, const char *s2)
{
return (*s1==*s2) ?
(*s1=='\0') ?
true
: strmatch(s1+1, s2+1)
: false;
}
template <unsigned N>
constexpr int index(const char (&array)[N])
{
return strmatch(array, "m0") ? 0 : -1;
}
template <int N>
constexpr int get() { return 1; }
template<unsigned N>
constexpr int extract(const char (&array)[N]) {
return get<index(array)>();
}
int main(void)
{
constexpr int i = strmatch("m0", "m0"); // OK
constexpr int j = index("m0"); // OK
constexpr int k = extract("m0"); // Not OK
}
More information about the Gcc-bugs
mailing list