[LLVMbugs] [Bug 13223] C++11 decltype sfinae static member function check

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jun 27 10:35:06 PDT 2012


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

Douglas Gregor <dgregor at apple.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Douglas Gregor <dgregor at apple.com> 2012-06-27 12:35:06 CDT ---
Clang is behaving correctly here. When you instantiate has_static<test>, we
have the binding T=test that is substituted into all of the declarations in
has_static. That leaves the first check() function to look like this:

  template<typename X>
    static std::true_type check(X*, decltype(test::fun())* = 0);

and Clang (correctly) complains that one cannot invoke test::fun without an
object argument.

GCC is allowed not to complain (templates don't have to be checked this early),
but the code is ill-formed for the reason that Clang is diagnosing.

You can fix the example by ensuring that the expression in decltype() can't be
substituted until we're in an actual SFINAE context, i.e., when we're
performing template argument deduction for 'check'. The fix is, simple, to use
X::fun instead:

template<typename X>
    static std::true_type check(X*, decltype(X::fun())* = 0);

-- 
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