1

I have a small program that compiles on GCC but not on MSVCwhich compiler isn't following the standard for constexpr string_view comparison?

#include <iostream>
#include <string_view>

int main(int argc, char **argv) {
    const constexpr auto a = "z";
    const constexpr std::string_view test("z",1);
    const constexpr std::string_view test2(a,1);
    if constexpr(test == test2) {
        return 5;
    }
    else{
        return 2;
    }
}
3
  • 3
    Which version of MSVS are you using? What error(s) do you get? Commented Apr 11, 2018 at 13:38
  • 1
    Apparently it will only compile with GCC 7.3 and not with the earlier versions. Commented Apr 11, 2018 at 13:42
  • I'm unfamiliar with MSVC versioning but from Compiler Explorer it looks like that version doesn't support if constexpr. This page details C++17 features and says "These features can be enabled by using the /std:c++17 version switch." If I add that switch on Compiler Explorer it tells me it's an unknown option. Have you tried running it locally with the latest MSVC? Commented Apr 11, 2018 at 13:49

1 Answer 1

3

C++17 constexpr if statements are supported since MSVC 19.11.

We can see in the error message that Compiler Explorer currently uses version 19.10.25017.

Sign up to request clarification or add additional context in comments.

3 Comments

removing the constexpr from the if statement and making a constexpr bool doesn't fix it however godbolt.org/g/JhwL2W
@Bomaz There appears to be a bug in MSVS's implementation of the string comparison. You should report it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.