LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 10735 - clang uses the regparm attribute when deciding templace specializations
Summary: clang uses the regparm attribute when deciding templace specializations
Status: RESOLVED INVALID
Alias: None
Product: clang
Classification: Unclassified
Component: C++ (show other bugs)
Version: unspecified
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-24 15:39 PDT by Rafael Ávila de Espíndola
Modified: 2011-08-24 16:18 PDT (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael Ávila de Espíndola 2011-08-24 15:39:50 PDT
Clang rejects and gcc accepts the following code:

template <typename Method> struct nsRunnableMethodTraits {
};
//template <class C> struct nsRunnableMethodTraits<void __attribute__ ((regparm (0))) (C::*)()> {
template <class C> struct nsRunnableMethodTraits<void (C::*)()> {
typedef int base_type;
};
template<typename Method> typename nsRunnableMethodTraits<Method>::base_type* NS_NewRunnableMethod(Method method) ;

struct C1  {
  virtual void __attribute__ ((regparm (0))) FinishStream(void) {
    NS_NewRunnableMethod(      &C1::FinishStream);
  }
};

Changing which line make clang accept the code.
Comment 1 Rafael Ávila de Espíndola 2011-08-24 15:40:24 PDT
Changing which line is commented...
Comment 2 Rafael Ávila de Espíndola 2011-08-24 15:59:25 PDT
The analogous case is that clang accepts

template <typename Method> struct nsRunnableMethodTraits;

template <class C> struct nsRunnableMethodTraits<void (C::*)()> {
  typedef int base_type;
};
template <class C> struct nsRunnableMethodTraits<void __attribute__ ((regparm (0))) (C::*)()> {
typedef int base_type;
};

and g++ rejects it:

nsUrlClassifierProxies.ii:7:27: error: redefinition of ‘struct nsRunnableMethodTraits<void (C::*)()>’
nsUrlClassifierProxies.ii:3:27: error: previous definition of ‘struct nsRunnableMethodTraits<void (C::*)()>’
Comment 3 Douglas Gregor 2011-08-24 16:18:08 PDT
Clang is behaving correctly here. A regparm-attributed member function pointer type is distinct from a non-regparm-attributed member function pointer type, so they'll have different template specializations. GCC's behavior appears to be inconsistent here, because the types are considered equivalent for the purposes of matching template arguments, so the regparm attribute associated with the first instantiation is the one that "sticks", even if subsequent instantiations don't have the regparm attribute.