This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/61312] New: variable function parameters declared as const in the class may not be declared as const in the function definition
- From: "alexis at m2osw dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 25 May 2014 22:41:10 +0000
- Subject: [Bug c++/61312] New: variable function parameters declared as const in the class may not be declared as const in the function definition
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61312
Bug ID: 61312
Summary: variable function parameters declared as const in the
class may not be declared as const in the function
definition
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: alexis at m2osw dot com
In the following code, the functions test() and foo() are both declared with a
flags parameter which is marked const. The declaration of the actual functions
(blah::foo() and blah::test() below the class declaration) do not specify the
const modifier and yet the compiler does not complain.
This happens with any number of parameters in the function declarations. It
does not happen with complex types (other classes) only basic types like int.
Since I may want to overload such functions, it is a problem. ("int" and "int
const" are not supposed to be the same type.)
class blah
{
public:
blah() {}
void test(int const flags);
private:
bool foo(int const flags);
int f_test;
};
bool blah::foo(int flags)
{
if(flags & 0x10)
{
f_test = 3;
}
else
{
f_test = 1;
}
return (flags & 0x03) != 0;
}
void blah::test(int flags)
{
flags |= 0x80;
foo(flags | 0x10);
}
int main()
{
blah a;
a.test(3);
return 0;
}