<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - ConvertDeclSpecToType mishandles cv-qualifiers on a function type"
   href="http://llvm.org/bugs/show_bug.cgi?id=16654">16654</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ConvertDeclSpecToType mishandles cv-qualifiers on a function type
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>james.widman@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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
'A<F>'
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
type.


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).</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>