Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libstdc++ doesn't recognise standard library literals

I'm trying to compile a simple program utilizing literals from the std::literals namespace, but Clang is generating errors when I try to compile it.

The code I'm trying to compile:

#include <string>
#include <iostream>

using namespace std::literals;

int main()
{
    std::cout << "Hello World!"s << std::endl;

    return 0;
}

and the compilation command:

clang++ -stdlib=libstdc++ -std=c++1y a.cpp

which leads to this output:

a.cpp:4:22: error: expected namespace name
using namespace std::literals;
                ~~~~~^
a.cpp:8:29: error: no matching literal operator for call to 'operator "" s' with arguments of
      types 'const char *' and 'unsigned long', and no matching literal operator template
        std::cout << "Hello World!"s << std::endl;
                                   ^
2 errors generated.

Using g++ or libc++ are out of the question for various reasons, and I've confirmed that other C++14 features (ie. return type deduction and binary literals) work, so it's not an issue with the compiler, making me believe it involves libstdc++.

What can I do to fix this? I'm on Linux Mint 17.1 if it makes any difference.

like image 798
user Avatar asked Oct 19 '22 03:10

user


1 Answers

Remember to ensure that you're compiling the source according to C++14 (the chrono literals are not provided in C++11).

clang++ -stdlib=libstdc++ -std=c++14 a.cpp
like image 66
bigov Avatar answered Nov 02 '22 09:11

bigov