5

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.

user
  • 51
  • 2
  • 1
    libstdc++ has support for this, so you must have an older version. – chris Aug 28 '15 at 04:27
  • Is there a way for me to check the version that I have installed? – user Aug 28 '15 at 04:54
  • You could follow the advice [here](http://stackoverflow.com/questions/10354636/how-do-you-find-what-version-of-libstdc-library-is-installed-on-your-linux-mac), but it's likely the same as GCC, so `gcc --version` should give the same answer. – chris Aug 28 '15 at 04:56
  • g++'s version is showing as 4.8.4 – user Aug 28 '15 at 05:38

1 Answers1

3

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
bigov
  • 141
  • 4