[LLVMbugs] [Bug 13309] New: [C++11] lack of backtrace for SFINAE'ed out functions a usability nightmare

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Jul 9 12:23:11 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13309

             Bug #: 13309
           Summary: [C++11] lack of backtrace for SFINAE'ed out functions
                    a usability nightmare
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: eric at boostpro.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


An extended discussion of this problem, including the suggestion from Doug
Gregor to file this bug, can be found here:
<https://groups.google.com/d/topic/boost-developers-archive/Ipn1bF24STc/discussion>

The gist of it is this:

    template<class T> auto h(T x)->decltype(x.smurf()){return x.smurf();}
    template<class T> auto g(T x)->decltype(h(x)){return h(x);}
    template<class T> auto f(T x)->decltype(g(x)){return g(x);}
    int main(){
      f(3);
    } 

Clang's (complete) error is:

1>  C:\cygwin\usr\local\bin\clang++ -c -O2 -DNDEBUG -std=gnu++11 -I../../..
-I/home/Eric/boost/org/trunk main.cpp -o main.o
1>  main.cpp:5:3: error: no matching function for call to 'f'
1>    f(3);
1>    ^
1>  main.cpp:3:24: note: candidate template ignored: substitution failure [with
T = int]: no matching function for call to 'g'
1>  template<class T> auto f(T x)->decltype(g(x)){return g(x);}
1>                         ^                ~
1>  1 error generated.

You will note that no mention is made of *why* g can't be called, or that h
can't be called because 'int' doesn't have a member function named 'smurf'. 

In contrast, g++'s error is far more informative:

1> main.cpp: In function ‘int main()’:
1> main.cpp:5:6: error: no matching function for call to ‘f(int)’
1> main.cpp:5:6: note: candidate is:
1> main.cpp:3:24: note: template<class T> decltype (g(x)) f(T)
1> main.cpp:3:24: note:   template argument deduction/substitution failed:
1> main.cpp: In substitution of ‘template<class T> decltype (g(x)) f(T) [with T
= int]’:
1> main.cpp:5:6:   required from here
1> main.cpp:3:24: error: no matching function for call to ‘g(int&)’
1> main.cpp:3:24: note: candidate is:
1> main.cpp:2:24: note: template<class T> decltype (h(x)) g(T)
1> main.cpp:2:24: note:   template argument deduction/substitution failed:
1> main.cpp: In substitution of ‘template<class T> decltype (h(x)) g(T) [with T
= int]’:
1> main.cpp:3:24:   required by substitution of ‘template<class T> decltype
(g(x)) f(T) [with T = int]’
1> main.cpp:5:6:   required from here
1> main.cpp:2:24: error: no matching function for call to ‘h(int&)’
1> main.cpp:2:24: note: candidate is:
1> main.cpp:1:24: note: template<class T> decltype (x.smurf()) h(T)
1> main.cpp:1:24: note:   template argument deduction/substitution failed:
1> main.cpp: In substitution of ‘template<class T> decltype (x.smurf()) h(T)
[with T = int]’:
1> main.cpp:2:24:   required by substitution of ‘template<class T> decltype
(h(x)) g(T) [with T = int]’
1> main.cpp:3:24:   required by substitution of ‘template<class T> decltype
(g(x)) f(T) [with T = int]’
1> main.cpp:5:6:   required from here
1> main.cpp:1:24: error: request for member ‘smurf’ in ‘x’, which is of
non-class type ‘int’

Insert appropriate discussion here about the pro's and con's of providing
detailed template instantiation backtraces. Doug seems to agree that clang is
providing too little here and that there is some room for improvement. I'll
leave it to the judgement of the clang team to decide how to best provide for
their users.

I will suggest, however, that this case is considered together with the more
general case of template instantiation failure. One approach that makes sense
to me -- and would meet my need and the needs of others on the boost list --
would be to show at least the start and end of the instantiation backtrace,
snipping the middle, and giving the user a command-line option for displaying
the full backtrace. The error message might even mention the command-line
option.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list