This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/62277] New: [C++11] constexpr member methods are treated as const, regardless of const modifier
- From: "juchem at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 27 Aug 2014 06:24:18 +0000
- Subject: [Bug c++/62277] New: [C++11] constexpr member methods are treated as const, regardless of const modifier
- Auto-submitted: auto-generated
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.