Should a class-scope typedef effect ODR?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We caught a bug report from the openSUSE folks. They are building with
LTO and -flto=6, and the new build flags generate ODR violations in
our library.

For example, this class:

template <class BASE, class SCHEME_OPTIONS, class KEY_CLASS>
class TF_ObjectImpl : public TF_ObjectImplBase<BASE, SCHEME_OPTIONS, KEY_CLASS>
{
public:
  typedef KEY_CLASS KeyClass;
  virtual ~TF_ObjectImpl() {}
  const KeyClass & GetKey() const {return m_trapdoorFunction;}
  KeyClass & AccessKey() {return m_trapdoorFunction;}
private:
  KeyClass m_trapdoorFunction;
};

Produces ODR findings when using LTO like:

pubkey.h:640:26: warning: type ‘struct TF_ObjectImpl’ violates the C++
One Definition Rule [-Wodr]
 class TF_ObjectImpl : public TF_ObjectImplBase<BASE, SCHEME_OPTIONS, KEY_CLASS>
...
pubkey.h:640:26: note: a different type is defined in another translation unit
 class TF_ObjectImpl : public TF_ObjectImplBase<BASE, SCHEME_OPTIONS, KEY_CLASS>
...
pubkey.h:651:11: note: the first difference of corresponding
definitions is field ‘m_trapdoorFunction’
  KeyClass m_trapdoorFunction;

When I remove the typedef and use KEY_CLASS directly:

template <class BASE, class SCHEME_OPTIONS, class KEY_CLASS>
class TF_ObjectImpl : public TF_ObjectImplBase<BASE, SCHEME_OPTIONS, KEY_CLASS>
{
public:
  // typedef KEY_CLASS KeyClass;
  virtual ~TF_ObjectImpl() {}
  const KeyClass & GetKey() const {return m_trapdoorFunction;}
  KeyClass & AccessKey() {return m_trapdoorFunction;}
private:
  KEY_CLASS m_trapdoorFunction;
};

Then the finding goes away.

As far as I know, this is boilerplate templated C++ code. There is no
cpu specific or platform specific code involved.

My first question is, should a class-scope typedef like used above effect ODR?

The problem above on occurs on ARM. i686, x86_64 and Aarch64 are OK
and do not generate findings. Someone on Stack Overflow claimed the
ARM compiler was correct, and the other platforms missed the finding.

My second question is, should I expect different behaviors for the
compiler on different platforms?

My final question is, which platform is correct? Is ARM correct and
the others incorrect; or is ARM incorrect and the others correct?

Thanks in advance.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux