[Bug c++/50958] New: [C++0x] raw literal operator provides incorrect string for integer literal '0'

daniel.kruegler at googlemail dot com gcc-bugzilla@gcc.gnu.org
Wed Nov 2 09:16:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50958

             Bug #: 50958
           Summary: [C++0x] raw literal operator provides incorrect string
                    for integer literal '0'
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: daniel.kruegler@googlemail.com
                CC: 3dw4rd@verizon.net


gcc 4.7.0 20111029 (experimental) in C++0x mode rejects the following code:

//---
typedef decltype(sizeof(0)) size_type;

constexpr size_type cstrlen_impl(const char* s, size_type i)
{
  return s[i] ? cstrlen_impl(s, i + 1) : i;
}

constexpr size_type cstrlen(const char* s)
{
  return s ? cstrlen_impl(s, 0) : throw 0;
}

constexpr size_type operator "" _lenraw(const char* digits)
{
  return cstrlen(digits);
}

static_assert(1_lenraw == 1, "Ouch"); // OK
static_assert(0_lenraw == 1, "Ouch"); // Error
//---

The error I'm getting is:

main.cpp|19|error: non-constant condition for static assertion|
main.cpp|19|  in constexpr expansion of 'operator"" _lenraw(0u)'|
main.cpp|15|  in constexpr expansion of 'cstrlen(digits)'|
main.cpp|10|error: expression '<throw-expression>' is not a
constant-expression|

This allows the conclusion, that the octal integer literal '0' is incorrectly
handled, instead of the expected string length of 1 the raw literal operator
gets a NULL string pointer. This seems to violate 2.14.8 p3 where 'n' would be
equal to '0' which should lead to the effective string literal argument "0" in
this case.



More information about the Gcc-bugs mailing list