Difficulty with multi-line raw string literals

Difficulty with multi-line raw string literals

I've been having trouble with multi-line raw string literals. This small program will illustrate:

#include <iostream>
#include <string>

using namespace std;

#pragma warning(disable : 1345)
const string grammar = R"!(
tokens

    <comment> : template = <slash_prefix_comment>

rules

    E ::= E '+' T | T
    T ::= T '*' F | F
    F ::= <number> | '(' E ')'

$)!";
#pragma warning(default : 1345)

int main()
{

    for (auto c: grammar)
    {
        cout << c << "   " << static_cast<int>(c) << endl;
    }

}

The pragma is to stop a warning about unterminated string literals. I don't think I should be getting that but I can live with the pragma. The last character to print here should be '$', but with version 14 of the compiler I get a few characters of junk instead of the '$'. With longer literals much more can be cut off. I gather this feature is intended for regex expressions but I'm trying to use it for something like a `here document', which would be longer. I think that should work too. Am I missing something?

3 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Best Reply

You're correct, it's a compiler bug. Is your host Windows or Linux?

It appears to be DPD200249078 in our internal bugs database. DPD200249078 has been fixed so it should be in the next update.

I'm using Windows. Thanks a lot for your help. I'll be looking forward to the next update.

Melden Sie sich an, um einen Kommentar zu hinterlassen.