[llvm-bugs] [Bug 31607] New: 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

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jan 11 06:01:26 PST 2017


https://llvm.org/bugs/show_bug.cgi?id=31607

            Bug ID: 31607
           Summary: 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
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: arphaman at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

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

template<class T = int>
struct A
{
    struct B {};

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

template<class T>
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<int>::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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170111/a8e03f26/attachment-0001.html>


More information about the llvm-bugs mailing list