[llvm-bugs] [Bug 39670] New: Unhelpful diagnostics when template parameters accidentally repeated after name

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 14 14:47:53 PST 2018


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

            Bug ID: 39670
           Summary: Unhelpful diagnostics when template parameters
                    accidentally repeated after name
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: comexk at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Here is some erroneous code where the list of template parameters is
accidentally repeated after the name of the item being declared:

--

// declaration #1
template <typename T>
void foo<T>() {}

struct X {
    // declaration #2
    template <typename T>
    void foo<T>() {}
    // declaration #3
    template <typename T>
    using Bar<T> = int;
};

--

(I sometimes make this error because writing the template parameters after the
name is necessary in C++ for partial specializations, and always done in some
other languages.)


However, the error messages are not as helpful as they could be:

--

/tmp/foo.cpp:2:6: error: variable has incomplete type 'void'
void foo<T>() {}
     ^
/tmp/foo.cpp:2:9: error: expected ';' at end of declaration
void foo<T>() {}
        ^
        ;
/tmp/foo.cpp:2:9: error: expected unqualified-id
/tmp/foo.cpp:6:10: error: function template partial specialization is not
allowed
    void foo<T>() {}
         ^  ~~~
/tmp/foo.cpp:8:5: error: cannot template a using declaration
    using Bar<T> = int;
    ^
/tmp/foo.cpp:8:14: error: expected member name or ';' after declaration
specifiers
    using Bar<T> = int;

--

Declaration #1 gets parsed as a variable declaration for some reason, even
though variable templates are equally ineligible for partial specialization.

Declaration #2 is closest to having a useful diagnostic ("function template
partial specialization is not allowed"), but it would be nice if Clang had a
more specific diagnostic suggesting removing the <T>.

For Declaration #3, the error message "cannot template a using declaration" is
outright inaccurate.  It *is* possible to template a using declaration, just
not to partially specialize one.

-- 
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/20181114/7b074523/attachment.html>


More information about the llvm-bugs mailing list