[Bug c++/83145] New: Ambiguous overload with templates, only GCC7 C++17 mode (regression?)

2017-11-24 Thread l.lunak at centrum dot cz
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83145

Bug ID: 83145
   Summary: Ambiguous overload with templates, only GCC7 C++17
mode (regression?)
   Product: gcc
   Version: 7.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: l.lunak at centrum dot cz
  Target Milestone: ---

The following code produces an ambiguous overload error only with GCC7 in C++17
mode. GCC6 is fine, GCC7 in C++14 mode is fine, Clang5 is fine, MSVC2015/2017
are fine. It would seem to me that the first overload is more specific and thus
should be the one selected.

==
template 
class Variant {
};

class BinaryOutputStream {
};

template 
BinaryOutputStream& operator<<(BinaryOutputStream& stream, const
Variant& /*variant*/) {
return stream;
}

template  class
TCollection,
  typename T,
  typename TAllocator,
  typename TCounter>
BinaryOutputStream& operator<<(BinaryOutputStream& ostream, const
TCollection& /*arr*/) {
return ostream;
}

int main()
{
Variant variant;
BinaryOutputStream stream;
stream << variant;
return 0;
}
=

$ g++-7 -Wall -Wextra a.cpp -c -std=gnu++17
a.cpp: In function ‘int main()’:
a.cpp:25:12: error: ambiguous overload for ‘operator<<’ (operand types are
‘BinaryOutputStream’ and ‘Variant’)
 stream << variant;
 ~~~^~
a.cpp:9:21: note: candidate: BinaryOutputStream&
operator<<(BinaryOutputStream&, const Variant&) [with TValues =
{float, int, char}]
 BinaryOutputStream& operator<<(BinaryOutputStream& stream, const
Variant& /*variant*/) {
 ^~~~
a.cpp:17:21: note: candidate: BinaryOutputStream&
operator<<(BinaryOutputStream&, const TCollection&)
[with TCollection = Variant; T = float; TAllocator = int; TCounter = char]
 BinaryOutputStream& operator<<(BinaryOutputStream& ostream, const
TCollection& /*arr*/) {
 ^~~~
$ g++-7 -Wall -Wextra a.cpp -c -std=gnu++14
$ g++-6 -Wall -Wextra a.cpp -c -std=gnu++17
$ clang++ -Wall -Wextra a.cpp -c -std=gnu++17
$ g++-7 -v
Using built-in specs.
COLLECT_GCC=g++-7
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/7/lto-wrapper
OFFLOAD_TARGET_NAMES=hsa:nvptx-none
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,fortran,ada,go
--enable-offload-targets=hsa,nvptx-none=/usr/nvptx-none, --without-cuda-driver
--enable-checking=release --disable-werror
--with-gxx-include-dir=/usr/include/c++/7 --enable-ssp --disable-libssp
--disable-libvtv --disable-libcc1 --disable-plugin
--with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux'
--with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit
--enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--with-default-libstdcxx-abi=gcc4-compatible
--enable-version-specific-runtime-libs --with-gcc-major-version-only
--enable-linker-build-id --enable-linux-futex --enable-gnu-indirect-function
--program-suffix=-7 --without-system-libunwind --enable-multilib
--with-arch-32=x86-64 --with-tune=generic --build=x86_64-suse-linux
--host=x86_64-suse-linux
Thread model: posix
gcc version 7.1.1 20170607 [gcc-7-branch revision 248970] (SUSE Linux)

[Bug c++/83145] Ambiguous overload with templates, only GCC7 C++17 mode (regression?)

2017-11-26 Thread l.lunak at centrum dot cz
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83145

--- Comment #3 from Luboš Luňák  ---
You are right, it is controlled by the -fnew-ttp-matching option. But while I
admit I have a problem deciphering what the referenced paper says in practice
or how it exactly applies to this case, this still looks broken to me. Consider
the following case, which is the original reduced to just one template argument
instead of 3:

=
template 
class Variant {
};

class BinaryOutputStream {
};

template 
BinaryOutputStream& operator<<(BinaryOutputStream& stream, const
Variant& /*variant*/) {
return stream;
}

template  class TCollection,
  typename T>
BinaryOutputStream& operator<<(BinaryOutputStream& ostream, const
TCollection& /*arr*/) {
return ostream;
}

int main()
{
Variant variant;
BinaryOutputStream stream;
stream << variant;
return 0;
}
=

That still triggers the error. Now remove the use of the variadic template
(i.e. remove those 3 cases of "..."), and now it compiles just fine.

Why should the use of a variadic template make any difference here? To me the
Variant overload looks like an obviously better match in both cases.

[Bug c++/66099] _Pragma diagnostic 'ignored' in macro with strict-overflow not suppressing warning fully with -Werror

2017-12-06 Thread l.lunak at centrum dot cz
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66099

Luboš Luňák  changed:

   What|Removed |Added

 CC||l.lunak at centrum dot cz

--- Comment #3 from Luboš Luňák  ---
I've noticed that using -save-temps also avoids the bug (I've run into a
similar problem).