[Bug c++/77660] New: Conversion operator unknown or ambiguous: gcc or clang behave differently

2016-09-20 Thread naupacte at sfr dot fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77660

Bug ID: 77660
   Summary: Conversion operator unknown or ambiguous: gcc or clang
behave differently
   Product: gcc
   Version: 5.4.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: naupacte at sfr dot fr
  Target Milestone: ---

In relation with bug #50306:
(using gcc5.4.1 or gcc6.1 from macports)

struct A;
struct B;

template  struct Ptr
{
template  operator const Ptr& () const;
#ifdef GCC_BUT_CLANG_DECLARES_IT_IS_AMBIGUOUS
template  operator   Ptr  () const; // required by gcc
but skipped for clang
#endif
};


const Ptr& foo1 (const Ptr& b) { return b;}//gcc ok 
  Ptr  foo2 (const Ptr& b) { return b;}// needs
GCC_BUT_CLANG_DECLARES_IT_IS_AMBIGUOUS to be set
  Ptr  foo2a(const Ptr& b) { return static_cast<Ptr>(b);} //gcc
patch


Who is right? Gcc cannot convert from const Ptr& to Ptr via const
Ptr&. I guess it has an influence on its inability to get the common type
for brace-lists or ?: pairs when only the reference conversion is given.

To avoid error: define GCC_BUT_CLANG_DECLARES_IT_IS_AMBIGUOUS only for gcc.
Otherwise, we get:

GCC

/opt/local/bin/gcc-mp-6 -x c++ -std=c++1y -c program.cpp

program.cpp: In function 'Ptr foo2(const Ptr&)':
program.cpp:22:47: error: could not convert 'b' from 'const Ptr' to 'Ptr'
   Ptr  foo2 (const Ptr& b) { return b;}// needs
GCC_BUT_CLANG_DECLARES_IT_IS_AMBIGUOUS to be set

CLANG
=

clang-mp-3.8 -x c++ -std=c++1y -c program.cpp
-DGCC_BUT_CLANG_DECLARES_IT_IS_AMBIGUOUS

program.cpp:22:47: error: conversion from 'const Ptr' to 'Ptr' is
ambiguous
  Ptr  foo2 (const Ptr& b) { return b;}// needs
GCC_BUT_CLANG_DECLARES_IT_IS_AMBIGUOUS to be set
  ^
program.cpp:13:76: note: candidate function [with U = A]
template  operator const Ptr& () const;
   ^
program.cpp:15:76: note: candidate function [with U = A]
template  operator   Ptr  () const;
   ^
program.cpp:23:47: error: ambiguous conversion for static_cast from 'const
Ptr' to 'Ptr'
  Ptr  foo2a(const Ptr& b) { return static_cast<Ptr>(b);} //gcc
patch
  ^~
program.cpp:11:27: note: candidate is the implicit copy constructor
template  struct Ptr
  ^
program.cpp:11:27: note: candidate is the implicit move constructor
2 errors generated.

[Bug c++/77658] New: internal compiler error: in assign_temp, at function.c:961

2016-09-20 Thread naupacte at sfr dot fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77658

Bug ID: 77658
   Summary: internal compiler error: in assign_temp, at
function.c:961
   Product: gcc
   Version: 6.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: naupacte at sfr dot fr
  Target Milestone: ---

//A very strange combination is needed to produce the ICE:
//Full program:

struct A
{
//A();
~A(); // NEEDED to produce ICE
};

#ifdef FIRST_CASE
A a (int) { throw ""; return {};}
A b (int) { throw ""; return {};}

A c (int) { throw ""; return {};}
A d (int) { throw ""; return {};}
A e (int) { throw ""; return {};}

#else // second case

A a (int) { throw 1;}
A b (int) { throw 1;}

A c (int) { throw 1;}
A d (int) { throw 1;}
A e (int) { throw 1;}

#endif
//EOF

NB: THERE MUST be at least 5 such functions:
- returning type A
- and throwing same type
- having one (unique?) same argument type





MacBookPro$  /opt/local/bin/gcc-mp-6 -x c++ -c .cpp  -O3
program.cpp: In function 'A a(int)':
program.cpp:16:3: internal compiler error: in assign_temp, at function.c:961
 A a (int) { throw 1;}
   ^

program.cpp:16:3: internal compiler error: Abort trap: 6
gcc-mp-6: internal compiler error: Abort trap: 6 (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://trac.macports.org/newticket> for instructions.


MacBookPro$ /opt/local/bin/gcc-mp-6 -v
Using built-in specs.
COLLECT_GCC=/opt/local/bin/gcc-mp-6
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin15/6.1.0/lto-wrapper
Target: x86_64-apple-darwin15
Configured with:
/opt/local/var/macports/build/_opt_mports_dports_lang_gcc6/gcc6/work/gcc-6.1.0/configure
--prefix=/opt/local --build=x86_64-apple-darwin15
--enable-languages=c,c++,objc,obj-c++,lto,fortran,java
--libdir=/opt/local/lib/gcc6 --includedir=/opt/local/include/gcc6
--infodir=/opt/local/share/info --mandir=/opt/local/share/man
--datarootdir=/opt/local/share/gcc-6 --with-local-prefix=/opt/local
--with-system-zlib --disable-nls --program-suffix=-mp-6
--with-gxx-include-dir=/opt/local/include/gcc6/c++/ --with-gmp=/opt/local
--with-mpfr=/opt/local --with-mpc=/opt/local --with-isl=/opt/local
--enable-stage1-checking --disable-multilib --enable-lto
--enable-libstdcxx-time --with-build-config=bootstrap-debug
--with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld
--with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket
--with-pkgversion='MacPorts gcc6 6.1.0_0'
Thread model: posix
gcc version 6.1.0 (MacPorts gcc6 6.1.0_0)

[Bug c++/68515] New: std::result_of<F(X)> doesn't work when F is abstract (with pure virtual functions)

2015-11-24 Thread naupacte at sfr dot fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68515

Bug ID: 68515
   Summary: std::result_of<F(X)> doesn't work when F is abstract
(with pure virtual functions)
   Product: gcc
   Version: 5.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: naupacte at sfr dot fr
  Target Milestone: ---

I had to replace 'typename std::result_of<F(X)>::type' by
'decltype(std::declval()(X()))'

All is in the title. Here is an example:

template ::type> vector
make_result(const vector& x, const F& f)
{
 auto n = x.size();
 vector y(n);
 for (uint i=0; i<n; i++) y[i] = f(x[i]);
 return y;
}

template  struct virtual_func
{
R operator()(T x) const { return _get(x);}

virtual R _get(T) const = 0;
}

template  struct virtual_sqrt : virtual_func<R,T>
{
virtual R _get(T x) const { return std::sqrt(x);}
}

std::vector sqrt(const std::vector& v)
{
   return make_result(v,virtual_sqrt{});
}


/opt/local/bin/gcc-mp-5 --version
gcc-mp-5 (MacPorts gcc5 5.2.0_0) 5.2.0

/opt/local/bin/gcc-mp-5 -x c++ -m64 -std=gnu++14 -c foo.cpp

>>>>>>>>>>>


error: no matching function for call to 'make_result(const vector&,
const virtual_func<double,double>&)'

note:   template argument deduction/substitution failed:
error: invalid abstract return type 'virtual_func'

template > vector
make_result(const vector& x, const F& f) { auto n = x.size(); vector
y(n); for (uint i=0; i<n; i++) y[i] = f(x[i]); return y;}
   ^
note:   because the following virtual functions are pure within
'virtual_func':
   template  struct virtual_func
  ^
note:   R virtual_func<R,T>::_get(T) const [with R = double; T = double]
virtual R _get(T) const = 0;


NB: here are the implementation details: