Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile-time error when using a raw string literal inside of REQUIRE (MSVC 2017) #274

Closed
agurtovoy opened this issue Aug 15, 2019 · 3 comments

Comments

@agurtovoy
Copy link

agurtovoy commented Aug 15, 2019

Description

The following test fails to compile on MSVC2017 (with /std:c++17 and /permissive- flags on):

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>

#include <string>

std::string foo( std::string const& ) { return ""; }

TEST_CASE( "[raw string literals]" ) 
{
    auto str = foo(R"(cl "-DNAME=\"Bob\"" test.cpp)"); // OK
    REQUIRE( foo(R"(cl "-DNAME=\"Bob\"" test.cpp)") == "" ); // Fails to compile
}
../main.cpp(11): error C2017: illegal escape sequence
../main.cpp(11): error C3688: invalid literal suffix 'Bob'; literal operator or literal operator template 'operator ""Bob' not found
../main.cpp(11): error C2661: 'doctest::detail::ResultBuilder::ResultBuilder': no overloaded function takes 3 arguments
n

Preprocessing the source file shows that the offending line expands to:

 do {  doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::DT_REQUIRE, "main2.cpp", 11, "foo(R\"(cl \"-DNAME=\\"Bob\\\"\" test.cpp)\") == \"\""); try { _DOCTEST_RB.setResult( doctest::detail::ExpressionDecomposer(doctest::assertType::DT_REQUIRE) << foo(R"(cl "-DNAME=\"Bob\"" test.cpp)") == ""); } catch(...) { _DOCTEST_RB.translateException(); } if(_DOCTEST_RB.log()) __debugbreak(); _DOCTEST_RB.react() ; } while((void)0, 0);

Escaping in the "foo(R\"(cl \"-DNAME=\\"Bob\\\"\" test.cpp)\") == \"\"" literal is problematic.

Steps to reproduce

All cl command flags (excluding -I paths):

"/MD" "/nologo" "/showIncludes" "/W3" "/EHsc" "/std:c++17" "/permissive-" "/Ob2" "/Gw" "/O2" "-D_CRT_SECURE_NO_WARNINGS" "-DNOMINMAX" "-O2" "-Ob2" "-MD" "-DNDEBUG"

Extra information

  • doctest version: v2.3.1
  • Operating System: Windows 10
  • Compiler+version: Microsoft (R) C/C++ Optimizing Compiler Version 19.11.25547 for x64
@onqtam
Copy link
Member

onqtam commented Aug 18, 2019

Strange that there's no problem with GCC/Clang... For now you can workaround it by using a local variable - I'll look at this at some point in the future... Thanks for reporting!

@agurtovoy
Copy link
Author

@onqtam Yep, that's what I did, just thought I'd report it. Could be a compiler bug, haven't tried it in VS2019 with /experimental:preprocessor on.

@onqtam
Copy link
Member

onqtam commented Sep 22, 2019

I can confirm that using /experimental:preprocessor fixes the problem, so I'll close this since it's an MSVC issue and there's nothing I can do anyway.

@onqtam onqtam closed this as completed Sep 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants