Bug 61312 - variable function parameters declared as const in the class may not be declared as const in the function definition
Summary: variable function parameters declared as const in the class may not be declar...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-25 22:41 UTC by Alexis Wilke
Modified: 2014-05-26 00:44 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexis Wilke 2014-05-25 22:41:10 UTC
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;
}
Comment 1 Jonathan Wakely 2014-05-25 22:46:15 UTC
Yes, that's how C++ works. Top-level const qualifiers are not part of a function signature.

This is not a bug, definitely not one with "major" severity!
Comment 3 Alexis Wilke 2014-05-26 00:44:38 UTC
Wow! I see that is now... "normal behavior". If you ask me, it sucks. But well... I suppose I don't count.

Thank you for the PDF reference.