Re: Compilation failure with std::result_of and SFINAE

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

 



On 7 March 2017 at 04:26, Veena Lakshmana wrote:
> Hello,
>
> I'm working on a project to move from GCC 4.9.3 to GCC 6.1
> In the process I've a hit a compilation failure which passed with GCC 4.9.3
>
> The reduced test case :
> ======================================
> #include <type_traits>
>
>
> namespace {
>
> struct foo {
>     template<class T, std::size_t = sizeof(T)>
>     std::false_type  operator()(T&);
>     std::true_type operator()(...);
> };
>
> struct FooIncomplete;
> }
>
>
> int main() {
>     std::result_of<foo(FooIncomplete&)>::type x;
>     return 0;
> }
> ========================================
>
> Error:
> unittest/tMetaIsIncomplete.cpp: In function ‘int main()’:
> unittest/tMetaIsIncomplete.cpp:38:5: error: ‘type’ is not a member of
> ‘std::result_of<{anonymous}::foo({anonymous}::FooIncomplete&)>’
>      std::result_of<foo(FooIncomplete&)>::type();
>      ^~~
>
> The above test case compiles fine with Clang 3.8 and Visual Studio 2015.
> Is this a regression with GCC ?

I don't think so, you can't invoke a foo with an argument of that type
because the first overload requires a complete type, and calling the
second overload with a class type is only conditionally-supported and
the compiler requires it to be complete to decide whether it can be
passed to the ... function.

> Am I doing something wrong here ?

Your code has an inherent bug, because the value of
result_of<foo(Incomplete&)>::value depends on where in the program
it's instantiated. If you ever use it when Incomplete is a complete
type you violate the One Definition Rule, producing undefined
behaviour.




[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