public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50958] New: [C++0x] raw literal operator provides incorrect string for integer literal '0'
@ 2011-11-02  9:16 daniel.kruegler at googlemail dot com
  2011-11-02 14:00 ` [Bug c++/50958] " 3dw4rd at verizon dot net
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2011-11-02  9:16 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-11-21 19:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-02  9:16 [Bug c++/50958] New: [C++0x] raw literal operator provides incorrect string for integer literal '0' daniel.kruegler at googlemail dot com
2011-11-02 14:00 ` [Bug c++/50958] " 3dw4rd at verizon dot net
2011-11-09 10:50 ` daniel.kruegler at googlemail dot com
2011-11-16 16:07 ` 3dw4rd at verizon dot net
2011-11-21 19:44 ` jason at gcc dot gnu.org
2011-11-21 20:23 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).