[LLVMbugs] [Bug 16654] New: ConvertDeclSpecToType mishandles cv-qualifiers on a function type

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Jul 18 10:35:18 PDT 2013


            Bug ID: 16654
           Summary: ConvertDeclSpecToType mishandles cv-qualifiers on a
                    function type
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: james.widman at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The following is well-formed C++11/1y, ill-formed C++2003, and
well-formed-but-with-undefined-behavior in C99:

typedef int F();
template<typename T> struct A {};
extern A<F> x;
extern A<F const > x;
extern A<F volatile > x;
extern A<F const volatile> x;

C++11 and C++1y say that the last three declarations of X are well-formed (but
redundant) because, as used above, "cv-qualifiers are ignored." [dcl.fct p6]

So in each declaration of x above, the canonical type is "A<function of ()
returning int>".

But with ToT (r186588), running:
clang++ -std=c++1y -stdlib=libc++ -pedantic -O3 -Wall -c t1.cpp

... Clang seems to behave as if the canonical type is different for each
declaration. Here's an excerpt:

t1.cpp:5:12: warning: qualifier on function type 'F' (aka 'int ()') has
unspecified behavior
extern A<F const > x;
t1.cpp:5:20: error: redefinition of 'x' with a different type: 'A<const F>' vs
extern A<F const > x;
t1.cpp:4:13: note: previous definition is here
extern A<F> x;

The "unspecified behavior" remark is better suited to C99.

And C++2003 says the program is ill-formed for trying to cv-qualify a function

The code issuing the diagnostic is ConvertDeclSpecToType() in .

I'm guessing that in lib/Sema/SemaType.cpp -> ConvertDeclSpecToType() -> "if
(Result->isFunctionType() && TypeQuals)", for C++ (all years), you would want:

  TypeQuals &= ~DeclSpec::TQ_const;

.. after giving a dialect-appropriate diagnostic. (Ditto for volatile.)

For C, status quo seems good (though maybe adjust the diagnostic to mention
undefined rather than unspecified behavior).

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/20130718/6d01a121/attachment.html>

More information about the llvm-bugs mailing list