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

* [Bug c++/50958] [C++0x] raw literal operator provides incorrect string for integer literal '0'
  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 ` 3dw4rd at verizon dot net
  2011-11-09 10:50 ` daniel.kruegler at googlemail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: 3dw4rd at verizon dot net @ 2011-11-02 14:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Ed Smith-Rowland <3dw4rd at verizon dot net> 2011-11-02 14:00:11 UTC ---
In http://gcc.gnu.org/ml/gcc-patches/2011-10/msg02804.html
I have a patch to address a resolution issue.

For some reason, this bug doesn't show up in that version.

I'll try to understand this bug but ultimately (and soon) I'd like to put a
version of that patch in and call it done.


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

* [Bug c++/50958] [C++0x] raw literal operator provides incorrect string for integer literal '0'
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2011-11-09 10:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2011-11-09 10:42:18 UTC ---
(In reply to comment #1)
I have now tested gcc 4.7.0 20111105, but the problem still seems to exist. I
can reproduce it on Windows XP 32 bit and Windows 7 64 bit.


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

* [Bug c++/50958] [C++0x] raw literal operator provides incorrect string for integer literal '0'
  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
  4 siblings, 0 replies; 6+ messages in thread
From: 3dw4rd at verizon dot net @ 2011-11-16 16:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Ed Smith-Rowland <3dw4rd at verizon dot net> 2011-11-16 16:03:26 UTC ---
Created attachment 25839
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25839
Patch to correctly resolve literal operators.

Literal operators were not properly resolved according to .  This means that
there could be mismatches between the literal and the literal operator that is
used to resolve it.

This patch also fixes this bug.


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

* [Bug c++/50958] [C++0x] raw literal operator provides incorrect string for integer literal '0'
  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
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2011-11-21 19:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2011-11-21 19:27:35 UTC ---
Author: jason
Date: Mon Nov 21 19:27:30 2011
New Revision: 181595

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181595
Log:
    PR c++/50958
gcc/cp/
    * parser.c (lookup_literal_operator): New.
    (cp_parser_userdef_char_literal): Use it.
    (cp_parser_userdef_numeric_literal): Use it.
    (cp_parser_userdef_string_literal): Use lookup_name.
libcpp/
    * expr.c (cpp_userdef_char_remove_type): Fix typo.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/udlit-implicit-conv-neg.C
    trunk/gcc/testsuite/g++.dg/cpp0x/udlit-raw-length.C
    trunk/gcc/testsuite/g++.dg/cpp0x/udlit-resolve.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/c-c++-common/dfp/pr33466.c
    trunk/gcc/testsuite/g++.dg/cpp0x/udlit-declare-neg.C
    trunk/gcc/testsuite/g++.dg/cpp0x/udlit-member-neg.C
    trunk/gcc/testsuite/g++.dg/cpp0x/udlit-raw-op-string-neg.C
    trunk/libcpp/ChangeLog
    trunk/libcpp/expr.c


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

* [Bug c++/50958] [C++0x] raw literal operator provides incorrect string for integer literal '0'
  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
                   ` (3 preceding siblings ...)
  2011-11-21 19:44 ` jason at gcc dot gnu.org
@ 2011-11-21 20:23 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2011-11-21 20:23 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |jason at gcc dot gnu.org
         Resolution|                            |FIXED
   Target Milestone|---                         |4.7.0

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2011-11-21 19:48:07 UTC ---
Fixed.


^ 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).