internal compiler arror in fold_convert_loc

Bug #1829790 reported by Dan Moodie
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-7 (Ubuntu)
Confirmed
Undecided
Unassigned
gcc-9 (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

With the build of GCC available in ubuntu 18.04, I get the following error when trying to compile this code:

// minimal example to break gcc 7 in the same way that the reflect code breaks it
#include <type_traits>

template<class T, class R, class ... ARGS>
struct MemberPointer
{
  R (T::* ptr)(ARGS...);
};

template<class T, class R, class ... ARGS>
constexpr MemberPointer<T, R, ARGS...> makeMemberPointer(R(T::* ptr)(ARGS...))
{
  return {ptr};
}

struct Foo
{
  static constexpr auto getField(std::integral_constant<int, 0>)
  {
    // This line breaks gcc
    return makeMemberPointer(static_cast<void(Foo::*)()>(&Foo::foo));

    // This line does not break gcc
    //return makeMemberPointer(&Foo::foo);
  }

  void foo(){}
};

template<class T>
struct Wrapper
{
  template<int I>
  static constexpr auto getField()
  {
    return T::getField(std::integral_constant<int, I>{});
  }
};

int main()
{
  // This line works fine either way
  Foo::getField(std::integral_constant<int, 0>{});
  // The offending line only breaks gcc when called through the Wrapper class
  Wrapper<Foo>::getField<0>();
}

error:
 internal compiler error: in fold_convert_loc, at fold-const.c:2530
         return T::getField(std::integral_constant<int, I>{});

Interestingly enough this bug is not present when I put this code into godbolt (https://godbolt.org/) which would indicate that it might be a difference in how the compilers were built.
The different flags between godbolt and ubuntu's built of gcc are as follows:

godbolt:
Configured with: ../gcc-7.4.0/configure --prefix=/opt/compiler-explorer/gcc-build/staging --disable-bootstrap --enable-clocale=gnu --enable-languages=c,c++,fortran --enable-ld=yes --enable-gold=yes --enable-lto --enable-plugins --with-pkgversion=GCC-Explorer-Build

ubuntu:
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.4.0-1ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --disable-werror --with-arch-32=i686 --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release

Dan Moodie (dtmoodie)
description: updated
description: updated
Revision history for this message
Matthias Klose (doko) wrote :

seen in GCC 6, 7, 8, not seen in GCC 9

Changed in gcc-7 (Ubuntu):
status: New → Confirmed
Matthias Klose (doko)
Changed in gcc-9 (Ubuntu):
status: New → Fix Released
Revision history for this message
Dan Moodie (dtmoodie) wrote :

I can confirm that this is fixed in gcc-9 using this repository: ppa:jonathonf/gcc-9.0

Revision history for this message
Dan Moodie (dtmoodie) wrote :

Building gcc7.4 from source does not have this problem.
https://gcc.gnu.org/gcc-7/

Revision history for this message
Dan Moodie (dtmoodie) wrote :

I forgot to mention that this works correctly in gcc 5.4 and possibly 4.9. I will double check 4.9 in the next few days.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.