public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug preprocessor/55971] New: Preprocessor macros with C++11 raw string literals fail to compile
@ 2013-01-14 15:23 nachms+gcc at gmail dot com
  2013-01-14 15:39 ` [Bug preprocessor/55971] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: nachms+gcc at gmail dot com @ 2013-01-14 15:23 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55971
           Summary: Preprocessor macros with C++11 raw string literals
                    fail to compile
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: nachms+gcc@gmail.com


It does not seem possible to create a macro which contains a C++ raw string
literal, when it should be.

Example:
-----------------
#include <iostream>

#define CREATE_CLIENTS R"(CREATE TABLE "clients"(
  "clientId" INTEGER PRIMARY KEY AUTOINCREMENT,
  "clientName" VARCHAR(64) UNIQUE
))"

int main()
{
  std::cout << CREATE_CLIENTS << std::endl;
  return 0;
}
-----------------
g++ -W -Wall -o test test.cpp -std=c++11
test.cpp:3:24: error: unterminated raw string
test.cpp:6:3: warning: missing terminating " character [enabled by default]
test.cpp:6:1: error: missing terminating " character
test.cpp:10:3: error: stray ‘R’ in program
test.cpp:4:3: error: expected unqualified-id before string constant

On the other hand, clang seems to be able to handle it:
clang++ -W -Wall -o test test.cpp -std=c++11
./test
CREATE TABLE "clients"(
  "clientId" INTEGER PRIMARY KEY AUTOINCREMENT,
  "clientName" VARCHAR(64) UNIQUE
)


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

* [Bug preprocessor/55971] Preprocessor macros with C++11 raw string literals fail to compile
  2013-01-14 15:23 [Bug preprocessor/55971] New: Preprocessor macros with C++11 raw string literals fail to compile nachms+gcc at gmail dot com
@ 2013-01-14 15:39 ` redi at gcc dot gnu.org
  2013-01-14 15:48 ` nachms+gcc at gmail dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2013-01-14 15:39 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-01-14 15:39:35 UTC ---
probably another dup of Bug 52852


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

* [Bug preprocessor/55971] Preprocessor macros with C++11 raw string literals fail to compile
  2013-01-14 15:23 [Bug preprocessor/55971] New: Preprocessor macros with C++11 raw string literals fail to compile nachms+gcc at gmail dot com
  2013-01-14 15:39 ` [Bug preprocessor/55971] " redi at gcc dot gnu.org
@ 2013-01-14 15:48 ` nachms+gcc at gmail dot com
  2013-01-14 15:56 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: nachms+gcc at gmail dot com @ 2013-01-14 15:48 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from Nach <nachms+gcc at gmail dot com> 2013-01-14 15:47:25 UTC ---
Does look similar. Although this bug here is in the definition of the macro,
while that bug is in the call of the macro.

I'm sure they're related, but it'd be a shame if one was fixed, and the other
was overlooked.


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

* [Bug preprocessor/55971] Preprocessor macros with C++11 raw string literals fail to compile
  2013-01-14 15:23 [Bug preprocessor/55971] New: Preprocessor macros with C++11 raw string literals fail to compile nachms+gcc at gmail dot com
  2013-01-14 15:39 ` [Bug preprocessor/55971] " redi at gcc dot gnu.org
  2013-01-14 15:48 ` nachms+gcc at gmail dot com
@ 2013-01-14 15:56 ` redi at gcc dot gnu.org
  2013-01-14 16:36 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2013-01-14 15:56 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-01-14 15:56:02 UTC ---
I think basically the preprocessor doesn't support raw strings.

Fix that and both bugs should go away.


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

* [Bug preprocessor/55971] Preprocessor macros with C++11 raw string literals fail to compile
  2013-01-14 15:23 [Bug preprocessor/55971] New: Preprocessor macros with C++11 raw string literals fail to compile nachms+gcc at gmail dot com
                   ` (2 preceding siblings ...)
  2013-01-14 15:56 ` redi at gcc dot gnu.org
@ 2013-01-14 16:36 ` jakub at gcc dot gnu.org
  2013-01-14 16:44 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-14 16:36 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-14 16:35:52 UTC ---
That's not the case, because most of the raw string support is in the
preprocessor.


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

* [Bug preprocessor/55971] Preprocessor macros with C++11 raw string literals fail to compile
  2013-01-14 15:23 [Bug preprocessor/55971] New: Preprocessor macros with C++11 raw string literals fail to compile nachms+gcc at gmail dot com
                   ` (3 preceding siblings ...)
  2013-01-14 16:36 ` jakub at gcc dot gnu.org
@ 2013-01-14 16:44 ` redi at gcc dot gnu.org
  2013-01-14 17:34 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2013-01-14 16:44 UTC (permalink / raw)
  To: gcc-bugs


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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-01-14
     Ever Confirmed|0                           |1

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-01-14 16:43:55 UTC ---
Thanks, Jakub, for some reason I thought it had ben done in the FE.

Let's confirm this then, it's not an exact dup.


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

* [Bug preprocessor/55971] Preprocessor macros with C++11 raw string literals fail to compile
  2013-01-14 15:23 [Bug preprocessor/55971] New: Preprocessor macros with C++11 raw string literals fail to compile nachms+gcc at gmail dot com
                   ` (4 preceding siblings ...)
  2013-01-14 16:44 ` redi at gcc dot gnu.org
@ 2013-01-14 17:34 ` jakub at gcc dot gnu.org
  2022-06-17 22:23 ` lhyatt at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-14 17:34 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org,
                   |                            |tromey at gcc dot gnu.org

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-14 17:33:02 UTC ---
This is about:
          if (pfile->state.in_directive
              || pfile->state.parsing_args
              || pfile->state.in_deferred_pragma)
            {
              cur--;
              type = CPP_OTHER;
              cpp_error_with_line (pfile, CPP_DL_ERROR, token->src_loc, 0,
                                   "unterminated raw string");
              break;
            }
in lex_raw_string, in this case state.in_directive is true, as it is in #define
directive.  But just removing state.in_directive from that condition isn't
enough,
1537          _cpp_process_line_notes (pfile, false);
1538          if (!_cpp_get_fresh_line (pfile))
doesn't handle this case correctly.


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

* [Bug preprocessor/55971] Preprocessor macros with C++11 raw string literals fail to compile
  2013-01-14 15:23 [Bug preprocessor/55971] New: Preprocessor macros with C++11 raw string literals fail to compile nachms+gcc at gmail dot com
                   ` (5 preceding siblings ...)
  2013-01-14 17:34 ` jakub at gcc dot gnu.org
@ 2022-06-17 22:23 ` lhyatt at gcc dot gnu.org
  2022-11-05 14:31 ` cvs-commit at gcc dot gnu.org
  2022-11-05 14:33 ` lhyatt at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: lhyatt at gcc dot gnu.org @ 2022-06-17 22:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55971

Lewis Hyatt <lhyatt at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lhyatt at gcc dot gnu.org

--- Comment #8 from Lewis Hyatt <lhyatt at gcc dot gnu.org> ---
I submitted a patch for this here:
https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596820.html

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

* [Bug preprocessor/55971] Preprocessor macros with C++11 raw string literals fail to compile
  2013-01-14 15:23 [Bug preprocessor/55971] New: Preprocessor macros with C++11 raw string literals fail to compile nachms+gcc at gmail dot com
                   ` (6 preceding siblings ...)
  2022-06-17 22:23 ` lhyatt at gcc dot gnu.org
@ 2022-11-05 14:31 ` cvs-commit at gcc dot gnu.org
  2022-11-05 14:33 ` lhyatt at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-11-05 14:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55971

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Lewis Hyatt <lhyatt@gcc.gnu.org>:

https://gcc.gnu.org/g:3ad2167bbac8ae83b1e91305b105ab5287bdac55

commit r13-3697-g3ad2167bbac8ae83b1e91305b105ab5287bdac55
Author: Lewis Hyatt <lhyatt@gmail.com>
Date:   Wed Jun 15 18:06:53 2022 -0400

    c++: libcpp: Support raw strings with newlines in directives [PR55971]

    It's not currently possible to use a C++11 raw string containing a newline
as
    part of the definition of a macro, or in any other preprocessing directive,
    such as:

     #define X R"(two
    lines)"

     #error R"(this error has
    two lines)"

    Add support for that by relaxing the conditions under which
    _cpp_get_fresh_line() refuses to get a new line. For the case of lexing a
raw
    string, it's OK to do so as long as there is another line within the
current
    buffer. The code in cpp_get_fresh_line() was refactored into a new function
    get_fresh_line_impl(), so that the new logic is applied only when
processing a
    raw string and not any other times.

    libcpp/ChangeLog:

            PR preprocessor/55971
            * lex.cc (get_fresh_line_impl): New function refactoring the code
            from...
            (_cpp_get_fresh_line): ...here.
            (lex_raw_string): Use the new version of get_fresh_line_impl() to
            support raw strings containing new lines when processing a
directive.

    gcc/testsuite/ChangeLog:

            PR preprocessor/55971
            * c-c++-common/raw-string-directive-1.c: New test.
            * c-c++-common/raw-string-directive-2.c: New test.

    gcc/c-family/ChangeLog:

            PR preprocessor/55971
            * c-ppoutput.cc (adjust_for_newlines): Update comment.

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

* [Bug preprocessor/55971] Preprocessor macros with C++11 raw string literals fail to compile
  2013-01-14 15:23 [Bug preprocessor/55971] New: Preprocessor macros with C++11 raw string literals fail to compile nachms+gcc at gmail dot com
                   ` (7 preceding siblings ...)
  2022-11-05 14:31 ` cvs-commit at gcc dot gnu.org
@ 2022-11-05 14:33 ` lhyatt at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: lhyatt at gcc dot gnu.org @ 2022-11-05 14:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55971

Lewis Hyatt <lhyatt at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |13.0
         Resolution|---                         |FIXED

--- Comment #10 from Lewis Hyatt <lhyatt at gcc dot gnu.org> ---
Fixed for GCC 13.

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

end of thread, other threads:[~2022-11-05 14:33 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-14 15:23 [Bug preprocessor/55971] New: Preprocessor macros with C++11 raw string literals fail to compile nachms+gcc at gmail dot com
2013-01-14 15:39 ` [Bug preprocessor/55971] " redi at gcc dot gnu.org
2013-01-14 15:48 ` nachms+gcc at gmail dot com
2013-01-14 15:56 ` redi at gcc dot gnu.org
2013-01-14 16:36 ` jakub at gcc dot gnu.org
2013-01-14 16:44 ` redi at gcc dot gnu.org
2013-01-14 17:34 ` jakub at gcc dot gnu.org
2022-06-17 22:23 ` lhyatt at gcc dot gnu.org
2022-11-05 14:31 ` cvs-commit at gcc dot gnu.org
2022-11-05 14:33 ` lhyatt 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).