mercredi 29 novembre 2017

g++ compile options with -std=c++14 compile error showing Werror=c++11-compat

my environment Arch Linux, gcc 7.2

I'm learning C++ and I'm using keyword constexpr to define a constant, while compile, it give me an error message error: identifier ‘constexpr’ is a keyword in C++11 [-Werror=c++11-compat]

I can compile my program with default g++, but cannot compile with -std=c++14 and -Werror

I believe the -Werror option caused the issue. but what is the issue? can someone tell me please?

#include<iostream>

int main(){
    constexpr double yen_dollar = 0.107;
    std::cout<<yen_dollar<<std::endl;
    return 0;
}


test.cpp:4:5: error: identifier ‘constexpr’ is a keyword in C++11 [-Werror=c++11-compat]
     constexpr double yen_dollar = 0.107;
     ^~~~~~~~~
4.4.1trythis.cpp: In function ‘int main()’:
4.4.1trythis.cpp:4:5: error: ‘constexpr’ was not declared in this scope
4.4.1trythis.cpp:5:16: error: ‘yen_dollar’ was not declared in this scope
     std::cout<<yen_dollar<<std::endl;

Aucun commentaire:

Enregistrer un commentaire