[llvm-bugs] [Bug 24422] New: typo correction leads to bogus "use 'template' keyword" diagnostic

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 10 13:18:29 PDT 2015


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

            Bug ID: 24422
           Summary: typo correction leads to bogus "use 'template'
                    keyword" diagnostic
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org,
                    rikka at google.com
    Classification: Unclassified

Testcase:

struct S { template<typename T> void Allocate(int); };
void f(S Filename) { SM.getAllocator().Allocate<char>(Filename.length() + 1); }

produces this:

<stdin>:1:77: error: use of undeclared identifier 'SM'
struct S { template<typename T> void Allocate(int); }; void f(S Filename) {
SM.getAllocator().Allocate<char>(Filename.length() + 1); }
                                                                            ^
<stdin>:1:95: error: no template named 'Allocate'; did you mean 'S::Allocate'?
struct S { template<typename T> void Allocate(int); }; void f(S Filename) {
SM.getAllocator().Allocate<char>(Filename.length() + 1); }
                                                                               
              ^~~~~~~~
                                                                               
              S::Allocate
<stdin>:1:38: note: 'S::Allocate' declared here
struct S { template<typename T> void Allocate(int); }; void f(S Filename) {
SM.getAllocator().Allocate<char>(Filename.length() + 1); }
                                     ^
<stdin>:1:119: error: no member named 'length' in 'S'
struct S { template<typename T> void Allocate(int); }; void f(S Filename) {
SM.getAllocator().Allocate<char>(Filename.length() + 1); }
                                                                               
                             ~~~~~~~~ ^

The second error here is bogus. We shouldn't have even tried that lookup, since
the LHS expression "SM.getAllocator()" resulted in an error. My original
testcase produced this even worse error:

/usr/local/google/home/richardsmith/build/llvm-9/src/tools/clang/lib/Serialization/ASTReader.cpp:1950:27:
error: use 'template' keyword to treat 'Allocate' as a dependent template name
        SM.getAllocator().Allocate<char>(Filename.length() + 1);
                          ^
                          template 
/usr/local/google/home/richardsmith/build/llvm-9/src/tools/clang/lib/Serialization/ASTReader.cpp:1950:9:
error: use of undeclared identifier 'SM'
        SM.getAllocator().Allocate<char>(Filename.length() + 1);
        ^
/usr/local/google/home/richardsmith/build/llvm-9/src/tools/clang/lib/Serialization/ASTReader.cpp:1950:51:
error: no member named 'length' in 'llvm::StringRef'
        SM.getAllocator().Allocate<char>(Filename.length() + 1);
                                         ~~~~~~~~ ^

... but I'm not sure what other pieces are needed to reproduce that error.
(Here, Filename is a StringRef and SM is undeclared. The enclosing context is
*not* a template, so the "dependent template name" diagnostic is completely
wrong.)

-- 
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/20150810/31740b0e/attachment-0001.html>


More information about the llvm-bugs mailing list