Skip to content

Clang accepts invalid code that mutates a const parameter when it is defined with a 'const' qualifier but declared without the 'const' in a class template #30955

@hyp

Description

@hyp
Bugzilla Link 31607
Version trunk
OS All
CC @DougGregor

Extended Description

Clang fails to report an error that it "cannot assign to variable 'b' with const-qualified type" given the following piece of code:

template
struct A
{
struct B {};

const B* test (const B* b) const;

};

template
inline auto A< T >::test (const B* const b) const -> const B*
{
return ++b; // expected an error here
}

int main()
{
A<> m;
const A<>::B* b = 0;
b = m.test (b);
}

The AST dumps show that the specialisation of method test from class A has the following parameter declaration:

ParmVarDecl 0x7fba11802228 <col:17, col:26> col:26 used b 'const struct A::B *'

but the non-specialised definition of the method test has the following parameter declaration:

ParmVarDecl 0x7fba11800e90 <col:27, col:42> col:42 referenced b 'const struct A::B *const'

This makes me think that the error isn't reported because the 'const' qualifier isn't given to the parameter in the specialised method definition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepts-invalidbugzillaIssues migrated from bugzillac++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions