[LLVMbugs] [Bug 7524] New: Problem with C++ default values, maybe a bad error message

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jun 29 13:40:31 PDT 2010


           Summary: Problem with C++ default values, maybe a bad error
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: kannan at cakoose.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com

Built Clang/LLVM trunk from 29 June 2010.

Code sample:

  template<class V>
  struct def_value {
    static V get();

  template <>
  struct def_value<int> {
    static int get() { return 0; }

  template <class V>
  V Test1(V value, V def_value = def_value<V>::get()) {
    return def_value;

  // Clang:
  //    Test.cc:17:42: error: 'V' does not refer to a value
  //    V Test1(V value, V def_value = def_value<V>::get()) {
  //                                             ^
  //    Test.cc:16:17: declared here
  //    template <class V>
  //                    ^

I think the error is that the parameter name "def_value" shadows the struct
named "def_value".  If I change the parameter name to something else, Clang
accepts it.

GCC accepts original code without complaint, though this might be incorrect

Either way, Clang's error message is confusing.  It looks like it might be
treating the '<' like an less-than operator and claiming that 'V' is not a
value.  It would be nice if it recognized that I'm trying to instantiate a

BTW, I'm not assuming that this is a huge issue or that it's easy to fix.  It's
just that you guys seem to have put in a lot of effort into good diagnostics,
which encourages people like me to file these kinds of bugs.  For example, I
wouldn't bother reporting this kind of problem to GCC (unfortunately).

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