[Bug c++/101194] New: 7.2 Regression

2021-06-24 Thread yannick.lepennec+gcc at live dot fr via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101194

Bug ID: 101194
   Summary: 7.2 Regression
   Product: gcc
   Version: 7.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yannick.lepennec+gcc at live dot fr
  Target Milestone: ---

Dear Maintainers,

Obligatory godbolt: https://godbolt.org/z/KnMnc7P57
Since GCC 7.2:

$ g++ -std=c++17 -Wall -Wextra -pedantic-errors

#include 

struct nodefault {
nodefault(int) {}
};

int main() {
std::array arr1{ nodefault{1} }; // OK
std::array arr2{ arr1[0] }; // Error???
}

Gives:

main.cpp: In function 'int main()':
main.cpp:9:44: error: no matching function for call to 'nodefault::nodefault()'
 std::array arr2{ arr1[0] }; // Error???
^
main.cpp:4:5: note: candidate: nodefault::nodefault(int)
 nodefault(int) {}
 ^
main.cpp:4:5: note:   candidate expects 1 argument, 0 provided
main.cpp:3:8: note: candidate: constexpr nodefault::nodefault(const nodefault&)
 struct nodefault {
^
main.cpp:3:8: note:   candidate expects 1 argument, 0 provided
main.cpp:3:8: note: candidate: constexpr nodefault::nodefault(nodefault&&)
main.cpp:3:8: note:   candidate expects 1 argument, 0 provided
main.cpp:9:44: error: no matching function for call to 'nodefault::nodefault()'
 std::array arr2{ arr1[0] }; // Error???
^
main.cpp:4:5: note: candidate: nodefault::nodefault(int)
 nodefault(int) {}
 ^
main.cpp:4:5: note:   candidate expects 1 argument, 0 provided
main.cpp:3:8: note: candidate: constexpr nodefault::nodefault(const nodefault&)
 struct nodefault {
^
main.cpp:3:8: note:   candidate expects 1 argument, 0 provided
main.cpp:3:8: note: candidate: constexpr nodefault::nodefault(nodefault&&)
main.cpp:3:8: note:   candidate expects 1 argument, 0 provided
main.cpp:9:44: error: no matching function for call to 'nodefault::nodefault()'
 std::array arr2{ arr1[0] }; // Error???
^
main.cpp:4:5: note: candidate: nodefault::nodefault(int)
 nodefault(int) {}
 ^
main.cpp:4:5: note:   candidate expects 1 argument, 0 provided
main.cpp:3:8: note: candidate: constexpr nodefault::nodefault(const nodefault&)
 struct nodefault {
^
main.cpp:3:8: note:   candidate expects 1 argument, 0 provided
main.cpp:3:8: note: candidate: constexpr nodefault::nodefault(nodefault&&)
main.cpp:3:8: note:   candidate expects 1 argument, 0 provided
main.cpp:9:44: error: no matching function for call to 'nodefault::nodefault()'
 std::array arr2{ arr1[0] }; // Error???
^
main.cpp:4:5: note: candidate: nodefault::nodefault(int)
 nodefault(int) {}
 ^
main.cpp:4:5: note:   candidate expects 1 argument, 0 provided
main.cpp:3:8: note: candidate: constexpr nodefault::nodefault(const nodefault&)
 struct nodefault {
^
main.cpp:3:8: note:   candidate expects 1 argument, 0 provided
main.cpp:3:8: note: candidate: constexpr nodefault::nodefault(nodefault&&)
main.cpp:3:8: note:   candidate expects 1 argument, 0 provided
main.cpp:9:44: error: no matching function for call to 'nodefault::nodefault()'
 std::array arr2{ arr1[0] }; // Error???
^
main.cpp:4:5: note: candidate: nodefault::nodefault(int)
 nodefault(int) {}
 ^
main.cpp:4:5: note:   candidate expects 1 argument, 0 provided
main.cpp:3:8: note: candidate: constexpr nodefault::nodefault(const nodefault&)
 struct nodefault {
^
main.cpp:3:8: note:   candidate expects 1 argument, 0 provided
main.cpp:3:8: note: candidate: constexpr nodefault::nodefault(nodefault&&)
main.cpp:3:8: note:   candidate expects 1 argument, 0 provided
main.cpp:9:44: error: no matching function for call to 'nodefault::nodefault()'
 std::array arr2{ arr1[0] }; // Error???
^
main.cpp:4:5: note: candidate: nodefault::nodefault(int)
 nodefault(int) {}
 ^
main.cpp:4:5: note:   candidate expects 1 argument, 0 provided
main.cpp:3:8: note: candidate: constexpr nodefault::nodefault(const nodefault&)
 struct nodefault {
^
main.cpp:3:8: note:   candidate expects 1 argument, 0 provided
main.cpp:3:8: note: candidate: constexpr nodefault::nodefault(nodefault&&)
main.cpp:3:8: note:   candidate expects 1 argument, 0 provided

---

GCC 7.2 and above accept the same code with -std=c++14. GCC 7.1 accepts it with
either. The error message seems to have gotten shorter in more recent GCC, but
is still present. I have bisected this to
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=0634d9fe36e8ced1c6046759f9ce1d2655c8d731

[Bug c++/86521] New: GCC 8 selects incorrect overload of ref-qualified conversion operator template

2018-07-14 Thread yannick.lepennec+gcc at live dot fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86521

Bug ID: 86521
   Summary: GCC 8 selects incorrect overload of ref-qualified
conversion operator template
   Product: gcc
   Version: 8.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yannick.lepennec+gcc at live dot fr
  Target Milestone: ---

Please consider the following code, built with `g++ -std=c++17 -Wall -Wextra
-pedantic`.
It used to be accepted by GCC 7.3, but this is no longer the case since GCC 8.
Godbolt for convenience: https://godbolt.org/g/oXFQex

It was broken since r258755, which makes this code ICE instead. The ICE itself
was fixed in r259123, but said fix now makes GCC reject it with the below
error.
This is still the case on today's r262658. As far as I can tell, GCC seems to
be incorrectly selecting the `const&` overload instead of the `&&` one.

#include 

template
struct require_cast {
T val;

template
explicit operator U () && {
return std::move(val);
}

template
explicit operator U const& () const& {
return val;
}
};

struct base {
base() = default;
base(base&&) = default;
base& operator=(base&&) = default;

base(base const&) = delete;
base& operator=(base const&) = delete;
};

struct derived : base {};

int main() {
require_cast d;
(void)static_cast(std::move(d));
(void)static_cast(std::move(d));
}


repro.c++: In function ‘int main()’:
repro.c++:34:41: error: use of deleted function ‘base::base(const base&)’
 (void)static_cast(std::move(d));
 ^
repro.c++:23:5: note: declared here
 base(base const&) = delete;
 ^~~~
repro.c++:35:44: error: use of deleted function ‘derived::derived(const
derived&)’
 (void)static_cast(std::move(d));
^
repro.c++:27:8: note: ‘derived::derived(const derived&)’ is implicitly deleted
because the default definition would be ill-formed:
 struct derived : base {};
^~~
repro.c++:27:8: error: use of deleted function ‘base::base(const base&)’
repro.c++:23:5: note: declared here
 base(base const&) = delete;
 ^~~~