https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85254

            Bug ID: 85254
           Summary: boost::is_final does not work for template types
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andysem at mail dot ru
  Target Milestone: ---

Created attachment 43868
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43868&action=edit
Preprocessed test case

This problem was initially reported to Boost here:

https://github.com/boostorg/type_traits/issues/66

The test case is this:

#include <boost/type_traits/is_final.hpp>
#include <type_traits>
#include <iostream>

struct final1 final {};
template <typename T> struct final2 final {};

int main() {
    std::cout << "boost::is_final<final1>: " << boost::is_final<final1>::value
<< std::endl;
    std::cout << "boost::is_final<final2<int>>::value: " << boost::is_final<
final2<int> >::value << std::endl;
    std::cout << "std::is_final<final1>::value: " <<
std::is_final<final1>::value << std::endl;
    std::cout << "std::is_final<final2<int>>::value: " << std::is_final<
final2<int> >::value << std::endl;
}

The output with gcc 6.4 and 7.2:

boost::is_final<final1>: 1
boost::is_final<final2<int>>::value: 0
std::is_final<final1>::value: 1
std::is_final<final2<int>>::value: 1

The expected output should be all 1s.

I suspect the compiler intrinsic __is_final produces incorrect result because
of remove_cv for some reason. boost::is_final is defined like this:

template <class T> struct is_final : public integral_constant<bool,
BOOST_IS_FINAL(typename remove_cv<T>::type)> {};

where BOOST_IS_FINAL is defined to __is_final. This is similar to std::is_final
except for the remove_cv trait. If I remove remove_cv then the test results are
as expected. remove_cv is implemented this way:

template <class T> struct remove_cv{ typedef T type; };
template <class T> struct remove_cv<T const>{ typedef T type;  };
template <class T> struct remove_cv<T volatile>{ typedef T type; };
template <class T> struct remove_cv<T const volatile>{ typedef T type; };

plus the similar specializations for array types, which are irrelevant to this
test.

Unfortunately, I could not reproduce the problem with a more reduced testcase,
including when I re-implemented is_final and remove_cv locally, so it's
possible that some surrounding code is at play.

I'm attaching a preprocessed source a compilable test code. Compile with:

g++ -I<path_to_boost> -o is_final_test is_final_test.cpp

I'm using Boost develop (pre-1.67), but the problem reproduces with Boost 1.62
that comes with Kubuntu 17.10 and likely any newer versions.

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
7.2.0-8ubuntu3.2' --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 --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--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
--enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3.2) 


$ g++-6 -v
Using built-in specs.
COLLECT_GCC=g++-6
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 6.4.0-8ubuntu1'
--with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs
--enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared
--enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie
--with-system-zlib --disable-browser-plugin --enable-java-awt=gtk
--enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre
--enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--with-target-system-zlib --enable-objc-gc=auto --enable-multiarch
--disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 6.4.0 20171010 (Ubuntu 6.4.0-8ubuntu1)

Reply via email to