https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62277
Bug ID: 62277 Summary: [C++11] constexpr member methods are treated as const, regardless of const modifier Product: gcc Version: 4.9.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: juchem at gmail dot com The following code fails to compile. Tested in Debian sid (g++ 4.8.3-9 and 4.9.1-9) and in http://ideone.com (gcc 4.8.1). Defining CONSTEXPR to an empty macro compiles and runs successfully. ---------------------------------------------- #include <iostream> #define CONSTEXPR constexpr struct foo { CONSTEXPR char const *bar() const { return "const"; } CONSTEXPR char const *bar() { return "non-const"; } }; int main() { foo f; std::cout << f.bar() << std::endl; foo const b; std::cout << b.bar() << std::endl; return 0; } ---------------------------------------------- output: prog.cpp:7:24: error: ‘constexpr const char* foo::bar() const’ cannot be overloaded CONSTEXPR char const *bar() { return "non-const"; } ^ prog.cpp:6:24: error: with ‘constexpr const char* foo::bar() const’ CONSTEXPR char const *bar() const { return "const"; } gcc versions in debian: $ g++-4.8 --version g++-4.8 (Debian 4.8.3-9) 4.8.3 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ g++-4.9 --version g++-4.9 (Debian 4.9.1-9) 4.9.1 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.