[Bug c++/116049] friend function with explicit object parameter

2024-07-24 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116049

--- Comment #1 from Fedor Chelnokov  ---
And this program
```
struct A {
friend bool operator == (this const A&, const A&) = default;
};

int main() {
A{} == A{};
}
```
results in 

internal compiler error: Segmentation fault
6 | A{} == A{};
  |  ^
0x202ef4c internal_error(char const*, ...)
???:0
0x7a50e0 build_new_op(op_location_t const&, tree_code, int, tree_node*,
tree_node*, tree_node*, tree_node*, tree_node**, int)
???:0
0x98a7a2 build_x_binary_op(op_location_t const&, tree_code, tree_node*,
tree_code, tree_node*, tree_code, tree_node*, tree_node**, int)
???:0
0x90e414 c_parse_file()
???:0
0xa0c4d9 c_common_parse_file()
???:0

Online demo: https://gcc.godbolt.org/z/zr6Y8vPss

[Bug c++/116049] New: friend function with explicit object parameter

2024-07-23 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116049

Bug ID: 116049
   Summary: friend function with explicit object parameter
   Product: gcc
   Version: 14.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program
```
struct A {
friend void f(this A);
};
```
is invalid because an explicit object parameter cannot appear in a non-member
function, but GCC accepts the declaration.

Online demo: https://gcc.godbolt.org/z/Taj4Ea1Px

[Bug c++/116020] Incorrect treatment of (this void) parameter

2024-07-22 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116020

--- Comment #1 from Fedor Chelnokov  ---
Another problematic problem example is as follows:

struct A {
static void f();
};

void foo() {
A::f(); //ok
}

void A::f(this void) {}

int main() {
A::f(); //error in GCC after A::f definition
}

Here the definition of declared no-argument member function with (this void) is
accepted but makes this function no longer callable. Clang has no issue with it
again. Online demo: https://gcc.godbolt.org/z/vKfzo7fe9

[Bug c++/116020] New: Incorrect treatment of (this void) parameter

2024-07-21 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116020

Bug ID: 116020
   Summary: Incorrect treatment of (this void) parameter
   Product: gcc
   Version: 14.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This C++23 program

struct A {
void f(this void) {}
};

int main() {
A{}.f();
}

is accepted by Clang, but GCC complains
> error: no matching function for call to 'A::f()'
> note:   candidate expects -1 arguments, 0 provided

Online demo: https://gcc.godbolt.org/z/hs6f8jv4h

Related discussion: https://stackoverflow.com/q/78773894/7325599

[Bug c++/115878] New: C++23: this int argument with value 0 considered as dereferencing a null pointer

2024-07-11 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115878

Bug ID: 115878
   Summary: C++23: this int argument with value 0 considered as
dereferencing a null pointer
   Product: gcc
   Version: 14.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This C++23 program
```
struct w { constexpr int f(this int x) { return x; } };
static_assert((*::f)(1) == 1); //ok in Clang and GCC
static_assert((*::f)(0) == 0); //ok in Clang, error in GCC
```
is fully accepted by Clang, but GCC complains about the last line:
> error: dereferencing a null pointer
which is at least not-consistent with the accepted previous line.

Online demo: https://gcc.godbolt.org/z/6rWon4no4

Original discussion: https://stackoverflow.com/q/78733013/7325599

[Bug c++/115858] New: Incompatibility of coroutines and alloca()

2024-07-10 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115858

Bug ID: 115858
   Summary: Incompatibility of coroutines and alloca()
   Product: gcc
   Version: 14.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program
```
#include 
#include 

struct ReturnObject {
  struct promise_type {
unsigned * value_ = nullptr;

void return_void() {}
ReturnObject get_return_object() {
  return {
.h_ = std::coroutine_handle::from_promise(*this)
  };
}
std::suspend_never initial_suspend() { return {}; }
std::suspend_never final_suspend() noexcept { return {}; }
void unhandled_exception() {}
  };

  std::coroutine_handle h_;
  operator auto() const { return h_; }
};

template
struct GetPromise {
  PromiseType *p_;
  bool await_ready() { return false; }
  bool await_suspend(std::coroutine_handle h) {
p_ = ();
return false;
  }
  PromiseType *await_resume() { return p_; }
};

ReturnObject counter()
{
  auto pp = co_await GetPromise{};

  //unsigned a[1]; auto & i = a[0]; //this version works fine
  auto & i = *new (alloca(sizeof(unsigned))) unsigned(0); //and this not
  for (;; ++i) {
pp->value_ = 
co_await std::suspend_always{};
  }
}

int main()
{
  std::coroutine_handle h = counter();
  auto  = h.promise();
  for (int i = 0; i < 5; ++i) {
std::cout << *promise.value_ << ' ';
h();
  }
  h.destroy();
}
```
prints `0 1 2 3 4` in Clang, but in GCC with -O2 flag it prints random numbers,
e.g. `1479544584 2 2 2 2`

Online demo: https://gcc.godbolt.org/z/E8GEKn3M9

Could you please clarify, whether alloca() is compatible with coroutines? And
if not, could you please add a diagnostic?

Original discussion: https://stackoverflow.com/q/67576168/7325599

[Bug c++/115818] New: Infinite recursive in noexcept operator is not detected

2024-07-07 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115818

Bug ID: 115818
   Summary: Infinite recursive in noexcept operator is not
detected
   Product: gcc
   Version: 14.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program
```
struct C {
void f() noexcept(noexcept(f())) {}
};
```
is rejected by both Clang and MSVC, because noexcept of f() is defined with
infinite recursion. But GCC accepts the program, which looks wrong.

Online demo: https://gcc.godbolt.org/z/abTc7sG4v

Original discussion: https://stackoverflow.com/q/74015227/7325599

[Bug c++/115596] New: Default arguments are erroneously allowed for parameters of a requires expression

2024-06-23 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115596

Bug ID: 115596
   Summary: Default arguments are erroneously allowed for
parameters of a requires expression
   Product: gcc
   Version: 14.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

GCC accepts invalid requires expression as follows with default arguments of a
parameter:
```
template
concept C = requires(T t = {}) {
t;
};
```
Both Clang and MSVC reject it.

Online demo: https://gcc.godbolt.org/z/EMncoT8Yv

[Bug c++/115594] New: requires expression permits arrays of voids

2024-06-22 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115594

Bug ID: 115594
   Summary: requires expression permits arrays of voids
   Product: gcc
   Version: 14.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program
```
template
concept C = requires(T t[2]) {
t;
};

static_assert(!C);
```
seems valid because arrays of voids are not allowed, and it is accepted by
Clang and MSVC. But in GCC static_assert evaluates to opposite value. Online
demo: https://gcc.godbolt.org/z/nM8Mj8qrb

[Bug c++/115504] New: Wrong decltype result for a captured reference inside limbda

2024-06-15 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115504

Bug ID: 115504
   Summary: Wrong decltype result for a captured reference inside
limbda
   Product: gcc
   Version: 14.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program
```
template int foo() = delete;
template<> int foo() { return 0; }

int main() { 
int y = 0;
int  = y;
return []() {
decltype(auto) x = i;
return foo();
}();
}
```
is accepted in Clang, MSVC and GCC 13.3, but not in GCC 14, which thinks that
`decltype(x)=int`. Online demo: https://gcc.godbolt.org/z/fc1nrP4P9

Related discussion: https://stackoverflow.com/a/78626163/7325599

[Bug c++/115471] New: Fail to capture (with initializer) constant bit-fields by reference in lambda expression

2024-06-13 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115471

Bug ID: 115471
   Summary: Fail to capture (with initializer) constant bit-fields
by reference in lambda expression
   Product: gcc
   Version: 14.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program
```
struct U {
int i : 4;
};

using CU = const U;

auto lm = [ = CU{5}.i]() { return y; };
```
is accepted by Clang and MSVC, and it shall be because when initializing a
const reference from a bit-field, a temporary is created (its type is the type
of the bit-field), copy initialized with the value of the bit-field, and the
reference is bound to that temporary.

But GCC fails here with the
error: cannot capture 'CU{5}.U::i' by reference

Online demo: https://gcc.godbolt.org/z/qnToW4qfY

Related discussion: https://stackoverflow.com/q/78611419/7325599

[Bug c++/115356] New: not a constant expression can be used as non-type template argument inside requires expression

2024-06-05 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115356

Bug ID: 115356
   Summary: not a constant expression can be used as non-type
template argument inside requires expression
   Product: gcc
   Version: 14.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

```
template 
struct A {};

constexpr bool foo(int v) {
 int && x = int{v};
 return requires { 
typename A;
typename A::T;
};
}

static_assert( foo(1) );
```

is rejected in Clang and MSVC, because `x` is not initialized by a constant
expression and because there is no type `A<1>::T`, but GCC accepts the program
just fine. Online demo: https://gcc.godbolt.org/z/o9oEee5ve

[Bug c++/115280] New: Concept can access private alias in a classs

2024-05-29 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115280

Bug ID: 115280
   Summary: Concept can access private alias in a classs
   Product: gcc
   Version: 14.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program
```
#include 

class A {
using X = int;
};

template
concept C = requires(T t) {
{ t } -> std::convertible_to;
};

static_assert(C);
```
is invalid and rejected by Clang with the error:
> error: 'X' is a private member of 'A'

But GCC accepts the program just fine, which looks wrong, online demo:
https://gcc.godbolt.org/z/nra6fExxG

[Bug c++/114654] New: Alias template cannot be found

2024-04-09 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114654

Bug ID: 114654
   Summary: Alias template cannot be found
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

```
template 
struct S {};

template
using A = S;

template
using B = A<[]{}>;

using C = B;
```

looks valid and it is accepted by Clang and MSVC, but GCC complains:
:10:11: error: 'B' does not name a type
   10 | using C = B;
Online demo: https://gcc.godbolt.org/z/P4ozcd6oW

Related discussion: https://stackoverflow.com/q/78292459/7325599

[Bug c++/114537] bit_cast does not work NSDMI of bitfields

2024-04-05 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114537

--- Comment #5 from Fedor Chelnokov  ---
Sorry, in above example I had to use `unsigned char` type:

```
#include 

struct A { unsigned char a : 7; };

static_assert( std::bit_cast(std::bit_cast(A{1})).a == 1 );
```

This program even after the fix in trunk, prints the same error as in the
original post:
:5:32:   in 'constexpr' expansion of 'std::bit_cast(std::bit_cast(A{1}))'
/opt/compiler-explorer/gcc-trunk-20240405/include/c++/14.0.1/bit:94:33: sorry,
unimplemented: '__builtin_bit_cast' cannot be constant evaluated because the
argument cannot be encoded
   94 |   return __builtin_bit_cast(_To, __from);

Online demo: https://gcc.godbolt.org/z/eqrsfGEnT

[Bug c++/114537] bit_cast does not work NSDMI of bitfields

2024-04-01 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114537

--- Comment #1 from Fedor Chelnokov  ---
Probably related:
```
#include 

struct A { int a: 7; };

static_assert( 1 == std::bit_cast(std::bit_cast(A{1})).a );
```
It looks valid and accepted by MSVC, but GCC prints:
error: '__builtin_bit_cast' accessing uninitialized byte at offset 0

Online demo: https://gcc.godbolt.org/z/3W5onY955

[Bug c++/114536] wrong constant evaluation of std::bit_cast for bit fields

2024-03-31 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114536

--- Comment #2 from Fedor Chelnokov  ---
May be just fail constant evaluation then instead of evaluating it to 0?

[Bug c++/114536] New: wrong constant evaluation of std::bit_cast for bit fields

2024-03-31 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114536

Bug ID: 114536
   Summary: wrong constant evaluation of std::bit_cast for bit
fields
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

In this program


#include 

struct A { unsigned char a: 7; };

struct B { unsigned char b; };

// fails in GCC
static_assert( std::bit_cast(A{1}).b == 1 );

int main() {
// correctly returns 1 in GCC
return std::bit_cast(A{1}).b;
}


static_assert fails with the message:

note: the comparison reduces to '(0 == 1)'

which contradicts runtime evaluation of the same expression. Online demo:
https://gcc.godbolt.org/z/fza4zas3E

[Bug c++/104282] Copy elision when initializing a base-class subobject with aggregate initialization

2024-03-22 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104282

--- Comment #8 from Fedor Chelnokov  ---
One more inconsistency here:

struct A {
  A() {} 
  A(A&&) = delete;
};

struct B : A { };

int main() {
// ok in GCC
B{ A{} };

// error in GCC
B b{ A{} };
}

GCC allows temporary creation B{ A{} }, but prohibits variable creation B b{
A{} }. Online demo: https://gcc.godbolt.org/z/YGjYYqo6M

It looks like both must be prohibited as in Clang (or both allowed as in MSVC).

Related discussion: https://stackoverflow.com/q/70898525/7325599

[Bug c++/114225] False positive -Werror=dangling-reference

2024-03-04 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114225

--- Comment #4 from Fedor Chelnokov  ---
Ok.

At the same time we see that some false positives of this warning are fixed in
Trunk, e.g.

struct A {
int i;
};

struct Getter {
const A * a;
const int & value() const { return a->i; }
};

int main() {
A a { .i = 1 };
const auto & i = Getter{  }.value();
return i;
}

Online demo: https://godbolt.org/z/z9rPx831n

So we assume that this one can be fixed as well, why not?

[Bug c++/114225] False positive -Werror=dangling-reference

2024-03-04 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114225

--- Comment #2 from Fedor Chelnokov  ---
Please note that this is a regression in GCC 13. GCC 12 (or other compilers) do
not show a warning here: https://godbolt.org/z/Yhfad47xs

[Bug c++/113755] New: Class without a viable destructor wrongly accepted

2024-02-04 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113755

Bug ID: 113755
   Summary: Class without a viable destructor wrongly accepted
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

template 
struct A {
  ~A() requires(sizeof(T) < 2);
};

int main() {
new A;
}

is ill formed per
https://timsong-cpp.github.io/cppwp/n4868/class.dtor#4.sentence-2 and rejected
by both Clang and MSVC with the errors:

* no viable destructor found
* error C7653: failed to select a destructor for the class

but GCC accepts it: https://godbolt.org/z/bqcs8WY3P

Related discussion: https://stackoverflow.com/a/77928824/7325599

[Bug c++/113713] New: static_assert result depends on optimization settings

2024-02-02 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113713

Bug ID: 113713
   Summary: static_assert result depends on optimization settings
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

struct A{};

constexpr bool p(auto) { return false; }
constexpr bool f(auto v) { return p(v); }
constexpr bool g() { return f(A()); }
constexpr bool p(A) { return true; }

static_assert( f(A{}) );

The static_assert passes in GCC only with -O0 command line option, and it fails
with -O1 and higher optimization options, which looks wrong. Online demo:
https://godbolt.org/z/vWq8G7rn4

Related discussion: https://stackoverflow.com/q/77923182/7325599

[Bug c++/113529] New: Incorrect result of requires-expression in case of function call ambiguity

2024-01-21 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113529

Bug ID: 113529
   Summary: Incorrect result of requires-expression in case of
function call ambiguity
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

In this program


#include 

struct A { 
auto operator <=>(const A&) const = default;
bool operator <(const A&) const = default;
};
struct B { 
auto operator <=>(const B&) const = default; 
};
struct C : A, B {};

template
concept Cmp = requires(T u, T v) { u < v; };

//auto cmp = C{} < C{}; //this correctly fails due to ambiguity
static_assert( !Cmp ); //but this evaluates wrongly in GCC


C{} < C{} is correctly rejected as ambiguous, but for some reason `requires` in
GCC returns that the objects can be compared. This program is accepted by Clang
truck (to be v18). Online demo: https://godbolt.org/z/76zoYMd6h

Explanation of ambiguity: https://stackoverflow.com/a/69245639/7325599

[Bug c++/113523] New: A conversion function template can have a deduced return type

2024-01-20 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113523

Bug ID: 113523
   Summary: A conversion function template can have a deduced
return type
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

Contrary to https://timsong-cpp.github.io/cppwp/n4861/class.conv.fct#6, GCC
allows  a conversion function template with a deduced return type:


struct A {
template
constexpr operator auto() const { return 1; }
};

constexpr int f() {
return A{}.template operator auto();
}

static_assert( f() == 1 );


Online demo: https://godbolt.org/z/s8oK6rnPY

In addition, the diagnostics "warning: use of 'auto' in member template
conversion operator can never be deduced" seems wrong.

[Bug libstdc++/113522] New: std::swap cannot be called with explicit template argument std::array

2024-01-20 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113522

Bug ID: 113522
   Summary: std::swap cannot be called with explicit template
argument std::array
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

#include 
#include 

int main() {
std::array a, b;
std::swap< std::array >( a, b ); 
}

is accepted by MSVC and Clang with libc++, but GCC with libstdc++ complains:

error: no matching function for call to 'swap
>(std::array&, std::array&)'

Online demo: https://godbolt.org/z/8xnd5PsfE

Related discussion: https://stackoverflow.com/q/77844837/7325599

[Bug libstdc++/113327] New: std::sleep_for(std::chrono::hours::max()) returns immediately

2024-01-10 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113327

Bug ID: 113327
   Summary: std::sleep_for(std::chrono::hours::max()) returns
immediately
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

Found in https://stackoverflow.com/a/77795017/7325599

The problem is that the following program returns immediately (instead of long
wait):


#include 
#include 
#include 

int main(int argc, char * argv[])
{
std::this_thread::sleep_for(std::chrono::hours::max());
}


Online demo: https://godbolt.org/z/vce44vjx5

[Bug c++/113303] New: One can assign to const reference in a template partial specialization

2024-01-09 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113303

Bug ID: 113303
   Summary: One can assign to const reference in a template
partial specialization
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program


template 
struct A;

template 
struct A{
  A() { a = 1; }
};

int x = 0;
A s;


is erroneously accepted by GCC despite the assignment to const reference.

Clang complains that "class template partial specialization is not more
specialized than the primary template".

And MSVC allows the specialization, but "you cannot assign to a variable that
is const"

Online demo: https://godbolt.org/z/1aPK8K311

[Bug c++/113272] Wrong specialization of class template selected

2024-01-09 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113272

--- Comment #2 from Fedor Chelnokov  ---
Here is simplified program without #include :


template 
struct A {};

template  requires requires(){ *p = 0; }
struct A {};

int x = 0;
struct B : A<>, A<(const int *)> {};


GCC fails here because of
error: duplicate base type 'A<(& x)>' invalid


Online demo: https://godbolt.org/z/aan59E6WE

[Bug c++/113272] New: Wrong specialization of class template selected

2024-01-08 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113272

Bug ID: 113272
   Summary: Wrong specialization of class template selected
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

#include 

template 
struct A;

template 
  requires std::same_as
struct A : std::false_type {};

template 
  requires std::same_as
struct A : std::true_type {};

int x = 0;
static_assert( A<>::value ); ///< try to comment this line
static_assert( !A<(const int *)>::value ); ///< GCC fails here

is accepted by Clang and MSVC, but GCC erroneously evaluates the last line.
Online demo: https://godbolt.org/z/5Pqx6TG3W

But if one comments the previous static_assert, then it starts working.

[Bug c++/113127] New: Unexpected error: '' was not declared 'constexpr'

2023-12-24 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113127

Bug ID: 113127
   Summary: Unexpected error: '' was not declared
'constexpr'
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This constexpr variable definition

constexpr bool b = ( delete [][]{ return new int[2]; }(), true );

is accepted in Clang and MSVC. But GCC complains:

:1:64: error: the value of '' is not usable in a
constant 
:1:56: note: '' was not declared 'constexpr'

Online demo: https://godbolt.org/z/ovso3neEr

[Bug c++/113113] New: False -Wmismatched-new-delete in case of destroying operator delete

2023-12-22 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113113

Bug ID: 113113
   Summary: False -Wmismatched-new-delete in case of destroying
operator delete
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

Consider the program as follows:


#include 

struct Shape {
void operator delete(Shape *, std::destroying_delete_t);
};

struct Triangle : Shape {};

void Shape::operator delete(Shape *p, std::destroying_delete_t) {
static_cast(p)->~Triangle();
::operator delete(p);
}

int main() {
Shape *p = new Triangle;
delete p;
}


GCC issues presumably false

warning: 'static void Shape::operator delete(Shape*, std::destroying_delete_t)'
called on pointer returned from a mismatched allocation function
[-Wmismatched-new-delete]

for this program as well as for longer original one from
https://stackoverflow.com/a/67595790/7325599

Online demo: https://godbolt.org/z/Pfc4PaGbd

[Bug c++/112775] New: Class template partial specialization with decltype(n) is wrongly rejected

2023-11-30 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112775

Bug ID: 112775
   Summary: Class template partial specialization with decltype(n)
is wrongly rejected
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

In this program


template 
class A;

template 
class A {};


class template A has one type parameter T, and two arbitrary non-type
parameters (of type T). And also a specialization of A is provided, having
equal non-type template parameters.

The program is accepted by Clang and MSVC, but not by GCC:

error: partial specialization 'class A' is not more
specialized than
5 | class A {};
  |   ^~~~
note: primary template 'template, T  > class
A'

Online demo: https://godbolt.org/z/qjYMn8bd6

[Bug c++/112744] New: Nested name specifier wrongly produces ambiguity in accessing static field

2023-11-28 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112744

Bug ID: 112744
   Summary: Nested name specifier wrongly produces ambiguity in
accessing static field
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

struct A { constexpr static int a = 0; };
struct B : A {};
struct C : A {};
struct D : B, C {};

int main() {
(void)D{}.a;   //ok everywhere
(void)D{}.A::a; //error in GCC
}

is accepted in Clang and MSVC, but GCC fails on the line with nested name
specifier:

error: 'A' is an ambiguous base of 'D'

Online demo: https://godbolt.org/z/vY6rjd9fx

[Bug c++/112620] New: Changes to the referenced object in exception handler are lost after rethrow

2023-11-19 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112620

Bug ID: 112620
   Summary: Changes to the referenced object in exception handler
are lost after rethrow
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

#include 

int main() {
int i;
try {
try {
throw (int*)0;
} catch (int*& p) {
p = 
throw;
}
}
catch (int*& p) {
printf("%p", (void*)p);
}
}

prints some not-null value in Clang and MSVC, which is correct according to
https://eel.is/c++draft/except.handle#15

> When the handler declares a reference to an object, any changes to the 
> referenced object are changes to the exception object and will have effect 
> should that object be rethrown.

But GCC prints (nil) here. Online demo: https://godbolt.org/z/n6s6bc17s

[Bug c++/112448] New: Constraint expression b rejected

2023-11-08 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112448

Bug ID: 112448
   Summary: Constraint expression b rejected
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

struct s { static constexpr bool v = true; };
template inline constexpr bool b = true;
constexpr bool f(auto x) requires b { return true; }
static_assert(f(s{})); // clang ok, gcc nope, msvc ok

is valid per the explanation here https://stackoverflow.com/a/77439003/7325599


but GCC rejects it with the error:

missing template arguments before '<' token
3 | constexpr bool f(auto x) requires b { return true; }
  |^
:3:36: error: expected initializer before '<' token
:4:15: error: 'f' was not declared in this scope
4 | static_assert(f(s{}));

Online demo: https://godbolt.org/z/1Gejvr4cn

[Bug tree-optimization/112346] [13 Regression] Wrong code produced with -O2

2023-11-02 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112346

--- Comment #4 from Fedor Chelnokov  ---
According to referenced stackoverflow discussion, the code is reduced from 
https://github.com/vermaseren/form see
https://github.com/vermaseren/form/issues/461

[Bug c/112346] New: Wrong code produced with -O2

2023-11-02 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112346

Bug ID: 112346
   Summary: Wrong code produced with -O2
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

#include 

char *SkipAName(char *s) {
  if (('A' <= *s && *s <= 'Z') || ('a' <= *s && *s <= 'z') ) {
while (isalnum(*s)) {
  s++;
}
  }
  return s;
}

int TestName(char *name) {
  while (*name)
name++;
  return 0;
}

int StrICmp(char *s1, char *s2) {
  while (*s1 && *s1 == *s2) {
s1++;
s2++;
  }
  return *s1 - *s2;
}

int DoTable(char *s) {
char *name, c;
name = s;
s = SkipAName(s);
c = *s;
*s = 0;
TestName(name);
*s = c;
if (*s == '(')
  return 3;
if (*s != ',')
  return 2;
*s = 0;
return StrICmp(name, "sparse");
}

int main() {
  char buf[] = "sparse,C(1)";
  return DoTable(buf);
}

shall return 0, but in GCC 13 with -O2 it returns 44. Online demo:
https://gcc.godbolt.org/z/c6W33T1zK

Related discussion: https://stackoverflow.com/q/77407156/7325599

[Bug c++/94264] Array-to-pointer conversion not performed on array prvalues

2023-10-08 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94264

Fedor Chelnokov  changed:

   What|Removed |Added

 CC||fchelnokov at gmail dot com

--- Comment #4 from Fedor Chelnokov  ---
Related discussion: https://stackoverflow.com/q/77051011/7325599

And an example from it:

int main() {
using U = int(&&)[1];
(void) *U{}; //ok everywhere

using T = int[1];
(void) *T{}; //error in GCC
}

Online demo: https://godbolt.org/z/4s8v9PPqT

[Bug libstdc++/111685] Segfault while sorting on array element address

2023-10-06 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111685

--- Comment #12 from Fedor Chelnokov  ---
Related discussion: https://stackoverflow.com/q/77224270/7325599

[Bug libstdc++/111685] Segfault while sorting on array element address

2023-10-04 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111685

--- Comment #10 from Fedor Chelnokov  ---
It seems that both libc++ and MS STL implement std::sort without a temporary
object passed to cmp, because they are fine with compiling the following code
in constant expression (where unrelated pointers cannot be compared):

consteval void foo() {
  std::array nums{1, 5, 4};
  auto cmp = [](auto& a, auto& b) { return  <  };
  std::sort(nums.begin(), nums.end(), cmp);
}

Online demo: https://godbolt.org/z/jdecfP6c4

Is it right that their implementations are less optimal because of no temporary
object?

[Bug tree-optimization/104165] [12 Regression] -Warray-bounds for unreachable code inlined from std::sort()

2023-09-27 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104165

--- Comment #10 from Fedor Chelnokov  ---
This issue happens in GCC 13.2 as well:
https://godbolt.org/z/TfGx3YccG

[Bug c++/104661] [C++17+] Catching exception by const value when exception-object has lvalue-reference constructor

2023-09-01 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104661

--- Comment #3 from Fedor Chelnokov  ---
Related discussion: https://stackoverflow.com/a/77021213/7325599

[Bug c++/111132] New: Function redeclaration in local scope breaks constant expression evaluation

2023-08-24 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32

Bug ID: 32
   Summary: Function redeclaration in local scope breaks constant
expression evaluation
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

constexpr bool bar(void) {
return true;
}

constexpr bool foo() {
constexpr bool bar(void);
return bar();
}

static_assert( foo() );


is accepted in Clang, but not in GCC, which prints


error: non-constant condition for static assertion
   10 | static_assert( foo() );
  |~~~^~
:10:19:   in 'constexpr' expansion of 'foo()'
:7:15: error: 'constexpr bool bar()' used before its definition
7 | return bar();
  |~~~^~

Online demo: https://godbolt.org/z/3PvoEx61x

[Bug c++/111113] New: Cannot define friend function of a local class in namespace scope

2023-08-23 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=13

Bug ID: 13
   Summary: Cannot define friend function of a local class in
namespace scope
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program defines friend function of a local class in namespace scope:

auto foo() {
struct A;
void bar(const A&);
struct A { 
friend void bar(const A&);
};
bar(A{});
return A{};
}

using A = decltype(foo());
void bar(const A&) {}


Both Clang and MSVC permit it, but GCC prints weird errors:

:5:21: error: 'void bar(const foo()::A&)', declared using local type
'const foo()::A', is used but never defined [-fpermissive]
5 | friend void bar(const A&);
  | ^~~
:5:21: error: 'void bar(const foo()::A&)' used but never defined
:12:6: warning: 'void bar(const A&)' defined but not used

Online demo: https://godbolt.org/z/Yqoeda94x

[Bug c++/110619] Dangling pointer returned from constexpr function converts in nullptr

2023-08-07 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110619

--- Comment #8 from Fedor Chelnokov  ---
Please note that GCC 13 also accepts invalid program (because dangling pointers
were converted in nullptr):

constexpr auto f(int a) {
return 
}

constexpr auto g(int b) {
return 
}

static_assert(f(1) <= g(2));

This program must be rejected because of relational comparison of unrelated
pointers as Clang and MSVC do, online demo: https://gcc.godbolt.org/z/q5z3Gvehe
And your patch fixes it as well, thanks.

[Bug c++/110642] New: Undefined behavior in same constant expression is found not always

2023-07-12 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110642

Bug ID: 110642
   Summary: Undefined behavior in same constant expression is
found not always
   Product: gcc
   Version: 13.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This lambda

auto f = [](int i) {
const auto y = i;
return [&] () {
return y;
};
};

returns another lambda that makes undefined behavior: it accesses a stack
variable (y) after the end of its life.

And it is successfully caught during constant expression evaluation by GCC and
other compilers, if verified like this:

constexpr auto g = f(3)();
static_assert( f(3)() == 3 );
Online demo: https://gcc.godbolt.org/z/3Y4cGMG15

But if one changes the order of lines:

static_assert( f(3)() == 3 );
constexpr auto g = f(3)();

then GCC stops detecting undefined behavior. Online demo:
https://gcc.godbolt.org/z/dojhKasPs

Could you please review why this happens?

[Bug c++/110619] Dangling pointer returned from constexpr function converts in nullptr

2023-07-10 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110619

--- Comment #3 from Fedor Chelnokov  ---
I think according to https://eel.is/c++draft/basic.stc#general-4 the function
shall return an "invalid pointer valued". And nullptr is not considered such.

And if one modifies the function slightly (see auto p appear):

constexpr auto g() {
int i = 0;
auto p = 
return p;
};

Then static_assert passes: https://gcc.godbolt.org/z/5shcxfcxG

[Bug c++/110619] New: Dangling pointer returned from constexpr function converts in nullptr

2023-07-10 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110619

Bug ID: 110619
   Summary: Dangling pointer returned from constexpr function
converts in nullptr
   Product: gcc
   Version: 13.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following function

constexpr auto f() {
int i = 0;
return 
};

returns dangling pointer on stack variable, but it is not nullptr. So next
assertion passes in Clang and MSVC:

static_assert( f() != nullptr );


But in GCC the assertion fails. Online demo:
https://gcc.godbolt.org/z/6E4rE963n

[Bug c++/110584] New: Constant is not visible in nested lambda

2023-07-07 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110584

Bug ID: 110584
   Summary: Constant is not visible in nested lambda
   Product: gcc
   Version: 13.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program (created by my colleague Artur)

void foo(float);
int main() {
constexpr float x = 0;
(void)[&] () {
foo(x);
(void)[] () {
foo(x);
};
};
}

is accepted in Clang and MSVC, but GCC complains:

error: 'x' is not captured
note: the lambda has no capture-default
'const float& x' declared here
5 | foo(x);

Online demo: https://gcc.godbolt.org/z/dY8bPhMYc

[Bug c++/110570] New: Error reading mutable subobject in constexpr when object lifetime began within the evaluation of E

2023-07-06 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110570

Bug ID: 110570
   Summary: Error reading mutable subobject in constexpr when
object lifetime began within the evaluation of E
   Product: gcc
   Version: 13.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

struct S {
mutable int i = 2;
};

constexpr auto f = []{
constexpr S s;
s.i = 3;
return s.i;
};

static_assert( f() == 3 );

is accepted in Clang, MSVC and ICC.

But GCC rejects the code with the error

  in 'constexpr' expansion of 'f.()'
error: mutable 'S::i' is not usable in a constant expression

Online demo: https://gcc.godbolt.org/z/Wsfeah3hq

It seems wrong, since lifetime of object s begins within the evaluation of
constant expression, see
https://timsong-cpp.github.io/cppwp/n4861/expr.const#5.16

Clang developers think that GCC is wrong here:
https://github.com/llvm/llvm-project/issues/63695

SO question: https://stackoverflow.com/q/76608087/7325599

[Bug c++/110513] New: Invalid use of incomplete type std::bool_constant inside requires expression

2023-07-01 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110513

Bug ID: 110513
   Summary: Invalid use of incomplete type std::bool_constant
inside requires expression
   Product: gcc
   Version: 13.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following program


#include 

struct B {
bool b = true;
};

// ok everywhere
static_assert( std::bool_constant{}() );

// error in GCC
static_assert( requires() { std::bool_constant{}(); } );


is accepted in Clang and MSVC, but GCC complains


:11:56: error: invalid use of incomplete type
'std::bool_constant'
   11 | static_assert( requires() { std::bool_constant{}(); } );
  | ~~~^~
In file included from :1:
/opt/compiler-explorer/gcc-13.1.0/include/c++/13.1.0/type_traits:62:12: note:
declaration of 'std::bool_constant'
   62 | struct integral_constant
  |^


Online demo: https://gcc.godbolt.org/z/csKanbM88

[Bug c++/110463] [13/14 Regression] Mutable subobject is usable in a constant expression

2023-07-01 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110463

--- Comment #5 from Fedor Chelnokov  ---
Thanks a lot for a very quick fix!

[Bug c++/110497] New: Wrong error on non-static data member referenced in concept definition

2023-06-30 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110497

Bug ID: 110497
   Summary: Wrong error on non-static data member referenced in
concept definition
   Product: gcc
   Version: 13.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

struct B {
const bool b = true;
};

template 
concept C = T::b;
static_assert( !C );

is accepted in Clang. And I think correctly accepted because of substitution
failure per https://eel.is/c++draft/temp.constr.constr#temp.constr.op-5

> [...] Furthermore, if substitution to determine whether an atomic constraint 
> is satisfied ([temp.constr.atomic]) encounters a substitution failure, the 
> constraint is not satisfied, regardless of the presence of a negation 
> operator.

But GCC emits a weird error (at least the error text must be adjusted):

error: '*(B*)(void)0' is not a constant expression

Online demo: https://gcc.godbolt.org/z/xKf13cb6v

[Bug c++/110463] New: Mutable subobject is usable in a constant expression

2023-06-28 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110463

Bug ID: 110463
   Summary: Mutable subobject is usable in a constant expression
   Product: gcc
   Version: 13.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following program is invalid per
https://timsong-cpp.github.io/cppwp/n4861/expr.const#4.8 (An object or
reference is usable in constant expressions if it is ... a non-mutable
subobject)

struct U {
mutable int x = 2;
};

int main() {
constexpr U u{};
u.x = 1;
static_assert( u.x == 2 ); // must fail, but ok in GCC
}

but GCC accepts it. Online demo: https://gcc.godbolt.org/z/n8MYzhbad

[Bug c++/110416] New: Error initializing of const union variable with a mutable field

2023-06-26 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110416

Bug ID: 110416
   Summary: Error initializing of const union variable with a
mutable field
   Product: gcc
   Version: 13.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

union U {
mutable int x;
float y = 2;
};

int main() {
const U u;
u.x = 1;
}

is accepted in Clang and MSVC, but GCC complains:

: In function 'int main()':
:7:13: error: uninitialized 'const u' [-fpermissive]
7 | const U u;
  | ^
:1:7: note: 'const union U' has no user-provided default constructor
1 | union U {
  |   ^
:2:17: note: and the implicitly-defined constructor does not initialize
'int U::x'
2 | mutable int x;

Online demo: https://gcc.godbolt.org/z/T8bqYTG5f

[Bug c++/110191] New: Alias template in function parameter does not match the nested type it refers to

2023-06-09 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110191

Bug ID: 110191
   Summary: Alias template in function parameter does not match
the nested type it refers to
   Product: gcc
   Version: 13.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

template
struct A {
struct Inner {};
void foo(Inner in);
};

template
using AInner = typename A::Inner;

template
void A::foo(AInner) {}

is valid and accepted in Clang and MSVC, but GCC complains:

error: no declaration matches 'void A::foo(AInner)'
   11 | void A::foo(AInner) {}
  |  ^~~~
:4:10: note: candidate is: 'void A::foo(Inner)'
4 | void foo(Inner in);
  |  ^~~
:2:8: note: 'struct A' defined here
2 | struct A {

Online demo: https://gcc.godbolt.org/z/5Pv9KW8vj

Related discussion: https://stackoverflow.com/q/76416600/7325599

[Bug libstdc++/110158] New: Cannot use union with std::string inside in constant expression

2023-06-07 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110158

Bug ID: 110158
   Summary: Cannot use union with std::string inside in constant
expression
   Product: gcc
   Version: 13.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

constexpr bool f() {
union U{
std::string s;
constexpr ~U(){ s.~basic_string(); }
} u{};
return true;
}

static_assert( f() );

is accepted in MSVC and Clang with libc++. But in GCC it produces the error:

error: non-constant condition for static assertion
   in 'constexpr' expansion of 'f()'
   in 'constexpr' expansion of '(& u)->f()::U::~U()'
   in 'constexpr' expansion of
'((f()::U*)this)->f()::U::s.std::__cxx11::basic_string::~basic_string()'
/opt/compiler-explorer/gcc-13.1.0/include/c++/13.1.0/bits/basic_string.h:803:19:
  in 'constexpr' expansion of
'((std::__cxx11::basic_string*)this)->std::__cxx11::basic_string::_M_dispose()'
error: accessing 'std::__cxx11::basic_string_M_allocated_capacity' member instead of initialized
'std::__cxx11::basic_string_M_local_buf' member in
constant expression

Online demo: https://gcc.godbolt.org/z/bbf4Yo3v9

[Bug c++/110114] New: ICE on calling overloaded function in case of incomplete argument type

2023-06-04 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110114

Bug ID: 110114
   Summary: ICE on calling overloaded function in case of
incomplete argument type
   Product: gcc
   Version: 13.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

struct A {
int a,b;
};

struct B;

void foo(const A &) {}
void foo(const B &) {}

int main() {
foo({.a=0});
}

is accepted by Clang and MSVC, but GCC 13 crashes on it with the message:

:11:8: internal compiler error: Segmentation fault
   11 | foo({.a=0});
  | ~~~^~~~
0x1ce67fe internal_error(char const*, ...)
???:0
0x751149 build_new_function_call(tree_node*, vec**, int)
???:0
0x8eaa5c finish_call_expr(tree_node*, vec**, bool,
bool, int)
???:0
0x89f99b c_parse_file()
???:0
0x98c2b9 c_common_parse_file()
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.

Online demo: https://godbolt.org/z/z7KPGrWsz

[Bug c++/109833] New: The value of constexpr anonymous union can be changed in runtime

2023-05-12 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109833

Bug ID: 109833
   Summary: The value of constexpr anonymous union can be changed
in runtime
   Product: gcc
   Version: 13.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The code as follows is accepted by GCC

constexpr static union {
  int k = 1;
};

int main() {
k = 10;
}
static_assert(k == 1);


yet crashes in runtime, online demo: https://gcc.godbolt.org/z/r5h7eEjde

[Bug c++/109523] New: List-initializing constructor of std::vector is selected erroneously

2023-04-15 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109523

Bug ID: 109523
   Summary: List-initializing constructor of std::vector is
selected erroneously
   Product: gcc
   Version: 12.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following program

#include 

struct C {
  int a;
  constexpr C() : a(0) {}
  constexpr C(int a) : a(a) {}
};

static_assert( std::vector({5}).size() == 5 );

is accepted in Clang and MSVC. But in GCC static assertion fails, because it
constructs a vector of single element 5. Online demo:
https://gcc.godbolt.org/z/j4b3z5xxP

Related discussion with explanation:
https://stackoverflow.com/q/76013629/7325599

[Bug c++/109159] New: explicit constructor is used in copy-initialization

2023-03-16 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109159

Bug ID: 109159
   Summary: explicit constructor is used in copy-initialization
   Product: gcc
   Version: 12.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following code must be accepted (as it does in Clang and MSVC):

struct A {
A( float ) {}
template
explicit A( U ) {}
};

template
concept CopyFromIntList = requires( T t ) { t = { 1 }; };

static_assert( !CopyFromIntList );

because 't = {1}' is invalid: chosen constructor is explicit in
copy-initialization.

But in GCC static_assert fails. Online demo:
https://gcc.godbolt.org/z/Pf47E6dno

[Bug c++/108588] __is_constructible returns wrong value for invalid (but non deleted) default constructor

2023-02-08 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108588

--- Comment #1 from Fedor Chelnokov  ---
According to this StackOverflow answer, the behavior of GCC is incorrect here:
https://stackoverflow.com/a/75380301/7325599

[Bug c++/108364] New: Construction from prvalue erroneously uses move-constructor

2023-01-10 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108364

Bug ID: 108364
   Summary: Construction from prvalue erroneously uses
move-constructor
   Product: gcc
   Version: 12.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

In the following code Bar default-constructor initializes its unmovable parent
Foo using a conversion operator creating a prvalue:

struct Foo {
Foo() = default;
Foo(Foo const&) = delete;
Foo(Foo&&) = delete;
};

Foo foo() { return {}; }

template
struct call_wrapper {
F&& f;

constexpr operator decltype(auto)() && {
return static_cast(f)();
}
};
template
call_wrapper(F&&) -> call_wrapper;

struct Bar : Foo {
Bar() : Foo(call_wrapper{foo}) {}
};

It works in Clang and MSVC, but unfortunately not in GCC, which prints
error: use of deleted function 'Foo::Foo(Foo&&)

Online demo: https://gcc.godbolt.org/z/3Wfdfb36a

This type of object construction was recommended in
https://stackoverflow.com/a/75068264/7325599

[Bug c++/107782] New: constexpr volatile variable is permitted to appear in a constant expression

2022-11-20 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107782

Bug ID: 107782
   Summary: constexpr volatile variable is permitted to appear in
a constant expression
   Product: gcc
   Version: 12.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

int main() {
constexpr volatile int i = 0;
constexpr volatile int j = i;
return j;
}

is properly rejected by Clang since according to
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4093.html#1688
constexpr volatile variable cannot appear in a constant expression.

Unfortunately GCC (and MSVC) accept invalid program. Online demo:
https://gcc.godbolt.org/z/43ee65Peq

Related discussion: https://stackoverflow.com/q/74511594/7325599

[Bug c++/107744] New: Error in constant evaluation of dynamic_cast

2022-11-17 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107744

Bug ID: 107744
   Summary: Error in constant evaluation of dynamic_cast
   Product: gcc
   Version: 12.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following program

struct A {
constexpr A();
virtual void f() {}
bool x;
};

struct B : A {};

constexpr A::A() { 
x = dynamic_cast(this);
}
constexpr bool b = B{}.x;

is accepted by Clang and MSVC, but GCC prints vague error:

:12:24:   in 'constexpr' expansion of 'B()'
:7:8:   in 'constexpr' expansion of '((B*)this)->B::.A::A()'
:12:24: error: '((&.B::) != 0)' is not a constant
expression
   12 | constexpr bool b = B{}.x;

Online demo: https://godbolt.org/z/1xdq68aaM

[Bug c++/107509] New: wrong ambiguous overloaded function error if argument class is undefined

2022-11-02 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107509

Bug ID: 107509
   Summary: wrong ambiguous overloaded function error if argument
class is undefined
   Product: gcc
   Version: 12.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

In the next program, struct B is only declared so foo(const B &) cannot be
called via foo({}):

struct A {};
struct B;

void foo(const A &) {}
void foo(const B &) {}

int main() {
foo({});
}

Clang and MSVC correctly call foo(const A &) here, but GCC prints the error:
call of overloaded 'foo()' is ambiguous

Online demo: https://godbolt.org/z/6fxYoxjc1

[Bug c++/107124] Reference template parameter refers to a temporary object

2022-10-30 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107124

--- Comment #3 from Fedor Chelnokov  ---
The latter example is indeed a bug in MSVC:
https://developercommunity.visualstudio.com/t/Cannot-find-template-function-with-expli/1672180

And here is the related discussion according the original issue:
https://stackoverflow.com/a/73921590/7325599

[Bug c++/107168] New: Wrong errors for concepts with default lambda not-type argument

2022-10-06 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107168

Bug ID: 107168
   Summary: Wrong errors for concepts with default lambda not-type
argument
   Product: gcc
   Version: 12.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following code in accepted in Clang and MSVC, but GCC emits seemingly wrong
errors:

template  concept x = true;
struct S {
// GCC error: template argument 2 is invalid
operator x auto() { return 42; }
// GCC error: wrong number of template arguments (0, should be at least 1)
operator x<> auto() const { return 43; }
};

Online demo: https://godbolt.org/z/a3494qrG3

[Bug c++/101670] Internal compiler error with concepts

2022-10-06 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101670

--- Comment #3 from Fedor Chelnokov  ---
A shorter example:

template  concept x = true;
void foo(x auto) {}

Online demo: https://godbolt.org/z/sT74G8crE

[Bug c++/107124] New: Reference template parameter refers to a temporary object

2022-10-02 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107124

Bug ID: 107124
   Summary: Reference template parameter refers to a temporary
object
   Product: gcc
   Version: 12.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following program is accepted by Clang:

template
struct A {};

template
constexpr int f(A) { return 0; }

template
constexpr int f(T) { return 1; }

static_assert( f(A<0>{}) == 1 );

But in GCC static assertion fails, because f(A) overload is preferred.
Online demo: https://gcc.godbolt.org/z/9hj4WoT7b

But this is illegal by http://eel.is/c++draft/temp.arg.nontype#3.1, since const
int & I cannot refer to a temporary int 0.

[Bug c++/106968] New: ignored noexcept(false) in explicitly-defaulted functions

2022-09-19 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106968

Bug ID: 106968
   Summary: ignored noexcept(false) in explicitly-defaulted
functions
   Product: gcc
   Version: 12.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This code is accepted in Clang and MSVC:
```
#include 

struct A {
A(A &&) noexcept(false) = default;
};

static_assert(!std::is_nothrow_move_constructible_v);
```
but in GCC static assertion fails, online demo: https://godbolt.org/z/x3Gz46Exe

[Bug c++/106599] Wrong copy elision in delegating to copy-constructor

2022-08-22 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106599

--- Comment #4 from Fedor Chelnokov  ---
And if one deletes copy constructor of A:

struct A {   
constexpr A() = default;
constexpr A(const A&) = delete;
constexpr A(int) : A(A()) {}
};

A a(2);

Then Clang rejects the program, but GCC accepts it (ignoring that selected
constructor is deleted), online demo: https://gcc.godbolt.org/z/s8Kjx6qPW

Is it ok?

[Bug libstdc++/106695] New: Regression 11,12: Explicit copy constructor does not work for a parameter passed via std::async

2022-08-20 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106695

Bug ID: 106695
   Summary: Regression 11,12: Explicit copy constructor does not
work for a parameter passed via std::async
   Product: gcc
   Version: 12.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program:
```
#include 

struct A {
A() = default;
explicit A(const A &) = default;
};

void foo(const A &) {}

int main() {
auto f = std::async(std::launch::async, foo, A{});
}
```
is accepted in GCC 10, MSVC and Clang with libc++, but not in GCC 11/12:

error: could not convert '{std::forward((* & __args#0)),
std::forward((* & __args#1))}' from '' to
'std::tuple'
 1693 |   _M_fn{{std::forward<_Args>(__args)...}}

Online demo: https://gcc.godbolt.org/z/nMn33PTbd

Related discussion: https://stackoverflow.com/q/73417828/7325599

[Bug c++/106599] New: Wrong copy elision in delegating to copy-constructor

2022-08-12 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106599

Bug ID: 106599
   Summary: Wrong copy elision in delegating to copy-constructor
   Product: gcc
   Version: 12.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following program should be valid:
```
struct A {   
int v = 0;
constexpr A() = default;
constexpr A(const A&) : v(1) {}
constexpr A(int) : A(A()) {}
};

static_assert( A(2).v == 1 );
```
and is accepted by Clang but not GCC. Online demo:
https://gcc.godbolt.org/z/zKoqq3rKW

Clang is probably correct here, because
http://eel.is/c++draft/class.base.init#7 says:

The expression-list or braced-init-list in a mem-initializer is used to
initialize the designated subobject (or, in the case of a delegating
constructor, the complete class object) according to the initialization rules
of [dcl.init] for direct-initialization.

So we should use the rules for direct-initialization and
http://eel.is/c++draft/dcl.init#general-16.6.2 says:

Otherwise, if the initialization is direct-initialization, or if it is
copy-initialization where the cv-unqualified version of the source type is the
same class as, or a derived class of, the class of the destination,
constructors are considered.
The applicable constructors are enumerated ([over.match.ctor]), and the best
one is chosen through overload resolution ([over.match]).

So we need to consider the constructors, and select A(const A&) : v(1)

[Bug tree-optimization/106247] GCC12 warning in Eigen: array subscript is partly outside array bounds

2022-07-10 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106247

Fedor Chelnokov  changed:

   What|Removed |Added

 CC||fchelnokov at gmail dot com

--- Comment #3 from Fedor Chelnokov  ---
Created attachment 53284
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53284=edit
Preprocessed source

Preprocessed source is attached.

[Bug c++/106247] New: GCC12 warning in Eigen: array subscript is partly outside array bounds

2022-07-10 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106247

Bug ID: 106247
   Summary: GCC12 warning in Eigen: array subscript is partly
outside array bounds
   Product: gcc
   Version: 12.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

If one compiles the following program using Eigen 3.4.0:

#include 

int main(){
Eigen::Array a;
a.setRandom();
Eigen::Array b;
b.col(0).tail(2) = a.col(1);
}


in GCC12 with command-line options: -std=c++20 -Wall -Wextra -pedantic-errors
-O2 -march=haswell
then a large error occurs ending with

/opt/compiler-explorer/gcc-12.1.0/lib/gcc/x86_64-linux-gnu/12.1.0/include/avxintrin.h:893:24:
warning: array subscript '__m256d_u[0]' is partly outside array bounds of
'Eigen::Array [1]' [-Warray-bounds]
  893 |   return *(__m256d_u *)__P;
  |^~~

Similar errors occur with other -march options or other code using Eigen
library.

Everything is fine in GCC 11 or other compilers. Online demo:
https://gcc.godbolt.org/z/hT348GYo9

Is it Eigen or GCC bug? Related discussion:
https://stackoverflow.com/q/72871100/7325599

[Bug c++/105699] [Concepts] Constrained virtual functions are accepted by GCC

2022-05-24 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105699

--- Comment #2 from Fedor Chelnokov  ---
Another aspect is that the order of destructors in the class change its
behavior:

#include 

template
struct X {
  ~X() requires (N==1);
  virtual ~X();
};

// X is NOT polymorphic in GCC
static_assert( !std::is_polymorphic_v> );

template
struct Y {
  virtual ~Y();
  ~Y() requires (N==1);
};

// Y is polymorphic in GCC
static_assert( std::is_polymorphic_v> );

Demo: https://gcc.godbolt.org/z/493qr5K9d

[Bug c++/105693] New: Requires-clause constructor is not selected

2022-05-22 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105693

Bug ID: 105693
   Summary: Requires-clause constructor is not selected
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

In the following program struct template A has deleted default constructor for
T=int:

#include 

template
struct A {
A() = default;
A() requires (std::same_as) = delete;
};

A a;

The program is rejected by Clang and MSVC, but not by GCC. Demo:
https://gcc.godbolt.org/z/G7T5xv35q

[Bug c++/105563] New: Consteval copy-constructor is allowed in not-constant expression

2022-05-11 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105563

Bug ID: 105563
   Summary: Consteval copy-constructor is allowed in not-constant
expression
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

In the following program, struct A has `consteval` copy-constructor, which is 
invoked in main() run-time via A{a1}:

struct A {
int i = 0;
A() {}
consteval A(const A&) = default;
};

int main() {
A a1;
A{a1};
}

Both Clang and MSVC reject this program, but not GCC. Demo:
https://gcc.godbolt.org/z/4G7ndne35

[Bug c++/105465] New: С++14 behaviour of inherited constructors broken

2022-05-03 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105465

Bug ID: 105465
   Summary: С++14 behaviour of inherited constructors broken
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

In the following program struct B inherits A(Foo) constructor, which is called
from main:

#include 

struct Foo {
Foo() {}
Foo(const Foo&) { std::cout << "Foo(const Foo&)\n"; }
};

struct A {
A(Foo) {}
};

struct B : A {
using A::A;
};

int main() {
Foo f;
B b(f);
}

According to C++14 standard
(https://timsong-cpp.github.io/cppwp/n4140/class.inhctor#8) the compiler shall
produce
B::B(Foo f) : A(f) { }

so the call `B(f)` leads to 2 copies of Foo and the program shall print:
Foo(const Foo&)
Foo(const Foo&)

And indeed GCC 6.4 prints so. But starting from GCC 7 only one copy is made.
Demo: https://gcc.godbolt.org/z/sTqKzdj5v

Related discussion: https://stackoverflow.com/a/56241478/7325599

Is it a regression?

[Bug c++/105407] New: std::construct_at during constant evaluation does not zero-initialize

2022-04-27 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105407

Bug ID: 105407
   Summary: std::construct_at during constant evaluation does not
zero-initialize
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This example program:
```
#include 
#include 

struct A {
int x = x;
};

constexpr int foo() {
A a{1};
std::construct_at();
return a.x;
}

int main() {
constexpr int v = foo();
std::cout << v << foo();
}
```
shall print "00" (as Clang and MSVC do), because before "x=x" std::construct_at
must zero-initialize (a), see https://eel.is/c++draft/dcl.init#general-9.1.2

GCC prints "10" (demo: https://gcc.godbolt.org/z/eoEr5KMjM) meaning that it
behaves correctly in run-time, but not during constant evaluation.

[Bug c++/105350] New: False constructor warning in case of [[depreacated]] field in class

2022-04-22 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105350

Bug ID: 105350
   Summary: False constructor warning in case of [[depreacated]]
field in class
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

In the following code the field (a) must not be initialized in the default
constructor of A:
```
struct A {
[[deprecated]] int a;
A() noexcept {}
};
```
but GCC prints the warning:
```
'A::a' is deprecated [-Wdeprecated-declarations]
```
Clang does not complain. Demo: https://gcc.godbolt.org/z/9s5dEr6jf

[Bug c++/88165] error: default member initializer for 'A::B::m' required before the end of its enclosing class

2022-04-22 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88165

--- Comment #11 from Fedor Chelnokov  ---
Thanks a lot for the explanation!

[Bug c++/104661] New: Catching exception by const value when exception-object has lvalue-reference constructor

2022-02-23 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104661

Bug ID: 104661
   Summary: Catching exception by const value when
exception-object has lvalue-reference constructor
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program
```
struct A {
A() {}
A(A&) {}
};

int main() {
try {
throw A{};
}
catch ( const A ) {
}
}
```
is presumably valid and accepted by Clang and MSVC, but GCC complains:
```
error: binding reference of type 'A&' to 'const A' discards qualifiers
   10 | catch ( const A ) {
  |   ^
:3:7: note:   initializing argument 1 of 'A::A(A&)'
3 | A(A&) {}
  |   ^~
```
Demo: https://gcc.godbolt.org/z/as671TGqs

[Bug c++/104000] Ordinary constructor cannot delegate to `consteval` constructor

2022-02-18 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104000

--- Comment #5 from Fedor Chelnokov  ---
Based on stackoverflow answer, a modified example was found with the delegation
to consteval constructor:
```
struct A {   
int i = 0;
consteval A() = default;
A(const A&) = delete;
A(int) : A(A()) {}
};
```
which is accepted in GCC. Demo: https://gcc.godbolt.org/z/5PjraK5ox

Clang rejects it until one remove `A(const A&) = delete`, which is probably
another issue.

[Bug c++/104512] New: [c++20] consteval constructor does not need to initialize all data members

2022-02-12 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104512

Bug ID: 104512
   Summary: [c++20] consteval constructor does not need to
initialize all data members
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

In the next program struct B has immediate consteval default constructor, which
does not initialize i field. Then this constructor is used to make a temporary
and its i field remains untouched:
```
struct B {
bool b = true;
int i;
consteval B() {}
};
static_assert( B{}.b );
```
Clang and MSVC are fine with it. But GCC complains:
 error: 'B{true}' is not a constant expression
7 | static_assert( B{}.b );
  |  ^
error: 'B()' is not a constant expression because it refers to an incompletely
initialized variable
Demo: https://gcc.godbolt.org/z/x4n6ezrhT

The requirement that "every non-variant non-static data member must be
initialized" in constexpr/consteval constructor is removed since c++20. Related
discussion: https://stackoverflow.com/a/71085832/7325599

[Bug c++/104490] New: Cannot inherit consteval constructor

2022-02-10 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104490

Bug ID: 104490
   Summary: Cannot inherit consteval constructor
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This code
```
struct B {
bool b = true;
consteval B(int) {}
};

struct C : B {
using B::B;
};

static_assert( C{1}.b );
```
looks valid and accepted in Clang and MSVC. But GCC rejects it with the error
```
:7:14: error: 'this' is not a constant expression
7 | using B::B;
  |  ^
:7:14: error: '' is not a constant expression
```
Demo: https://gcc.godbolt.org/z/fzajKzobn

[Bug c++/104418] [C++17+] Error inheriting base class constructors by using-declaration

2022-02-08 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104418

--- Comment #7 from Fedor Chelnokov  ---
Thanks. I submitted Clang bug:
https://github.com/llvm/llvm-project/issues/53653

[Bug c++/104418] Error inheriting base class constructors by using-declaration

2022-02-07 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104418

--- Comment #4 from Fedor Chelnokov  ---
I think `using B::B;` is not the same as redefining each constructor with the
explicit call of base class constructor `C(int a) : B{(int)a}{}`.

Please consider this example proving it:
```
struct A {
A() {}
A(const A&) = delete;
};

struct B {
B(A) {}
};

// ok everywhere
struct C : B {
using B::B;
};

//error everywhere
struct D : B {
D(A a) : B(a) {}
};
```

Here struct C definition is fine, but struct D is ill-formed because it
requires A to be copyable. Demo: https://gcc.godbolt.org/z/T7bhv9jeP

[Bug c++/104418] Error inheriting base class constructors by using-declaration

2022-02-07 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104418

--- Comment #2 from Fedor Chelnokov  ---
My personal feeling is that if a compiler accepts `B b(i);` then it must accept
`C c(i);` as well because of [namespace.udecl] p13:

> Constructors that are named by a using-declaration are treated as though they 
> were constructors of the derived class when looking up the constructors of 
> the derived class ([class.qual]) or forming a set of overload candidates 
> ([over.match.ctor], [over.match.copy], [over.match.list]).

But probably I miss something.

[Bug c++/104418] New: Error inheriting base class constructors by using-declaration

2022-02-07 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104418

Bug ID: 104418
   Summary: Error inheriting base class constructors by
using-declaration
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This code
```
struct B {
B(int) {}
B(int&&) {}
};

int i = 1;
B b(i); //ok everywhere

struct C : B {
using B::B;
};

C c(i); //ok in Clang only
```
is accepted in Clang, but GCC complains:
```
:13:6: error: use of deleted function 'C::C(int) [inherited from B]'
   13 | C c(i);
  |  ^
:10:14: note: 'C::C(int) [inherited from B]' is implicitly deleted
because the default definition would be ill-formed:
   10 | using B::B;
  |  ^
:10:14: error: call of overloaded 'B(int)' is ambiguous
```
Demo: https://gcc.godbolt.org/z/79EoYM94d

Related question: https://stackoverflow.com/q/71005539/7325599

[Bug c++/83264] std::initializer_list with a single element selects the wrong overload

2022-02-05 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83264

--- Comment #9 from Fedor Chelnokov  ---
There is a related discussion: https://stackoverflow.com/a/47618530/7325599

And it is noted there that according to [over.ics.rank]/2 just before
[over.ics.rank]/3:
— a standard conversion sequence is a better conversion sequence than a
user-defined conversion

[Bug c++/104383] New: User-defined conversion is preferred over standard-one

2022-02-04 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104383

Bug ID: 104383
   Summary: User-defined conversion is preferred over standard-one
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This example
```
#include 

struct IntSimilar { constexpr IntSimilar(int) {} };

constexpr int f(int) { return 1; }
constexpr int f(std::initializer_list) { return 2; }

int main() {
static_assert( f({0}) == 1 );
}
```
is accepted by Clang and MSVC. It looks right according to the standard saying
"a standard conversion sequence is a better conversion sequence than a
user-defined conversion sequence"
https://timsong-cpp.github.io/cppwp/n4861/over.ics.rank#2.1

But GCC selects the other overload. Demo: https://gcc.godbolt.org/z/3Ghvn98xr

[Bug c++/104305] New: Partial specialization with parameter pack is ignored

2022-01-31 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104305

Bug ID: 104305
   Summary: Partial specialization with parameter pack is ignored
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program:
```
#include 

template class TT, typename T1>
class A {};

template
struct is_a : std::false_type {};

template class TT, typename... T>
struct is_a> : std::true_type {};

template
struct TT {};

int main() {
static_assert( is_a>::value );
}
```
is accepted in Clang and MSVC, but not in GCC, where static_assert is violated.
Demo: https://gcc.godbolt.org/z/d5s9hzaca

Related discussion: https://stackoverflow.com/q/52129797/7325599

[Bug libstdc++/92770] std::unordered_map requires both T and U to be fully declared

2022-01-30 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92770

Fedor Chelnokov  changed:

   What|Removed |Added

 CC||fchelnokov at gmail dot com

--- Comment #2 from Fedor Chelnokov  ---
I see that this issue is fixed in GCC trunk. Demo:
https://gcc.godbolt.org/z/Gz5WY495Y

Was it intentionally or by accident?

[Bug c++/104266] Temporaries with protected destructor are erroneously permitted

2022-01-29 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104266

--- Comment #4 from Fedor Chelnokov  ---
In your last example, I think Clang is right, because `Y` is not an aggregate
in C++11 due to the presence of default member initializer. And it becomes an
aggregate only in C++14.

[Bug c++/104282] Copy elision when initializing a base-class subobject with aggregate initialization

2022-01-29 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104282

--- Comment #3 from Fedor Chelnokov  ---
Both Clang and GCC do not change their output either with `-std=c++20` or with
`-std=c++17` options. And both reject the program with -std=c++14`.

[Bug c++/88417] partial specialization of static template variable inside class template gives wrong result

2022-01-29 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88417

Fedor Chelnokov  changed:

   What|Removed |Added

 CC||fchelnokov at gmail dot com

--- Comment #3 from Fedor Chelnokov  ---
Even more reduced example. Below program is accepted in Clang and MSVC:
```
template 
struct Y {
   static constexpr T2 x{0};
};  

template<>
constexpr int Y::x{1};

int main() {
static_assert(Y::x == 1);
}
```
but GCC complains:
```
duplicate initialization of 'Y::x'
```
Demo: https://gcc.godbolt.org/z/TbP18z9Yq

Related discussion: https://stackoverflow.com/q/53687873/7325599

[Bug c++/104282] New: Copy elision when initializing a base-class subobject with aggregate initialization

2022-01-29 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104282

Bug ID: 104282
   Summary: Copy elision when initializing a base-class subobject
with aggregate initialization
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The program
```
#include 

struct A {
  A() { std::cout << "A "; } 
  A(const A&) { std::cout << "Acopy "; } 
  A(A&&) { std::cout << "Amove "; } 
  ~A() { std::cout << "~A "; }
};

struct B : A { };

int main() {
B b{ A{} };
}
```
if compiled by GCC, prints `A ~A `, showing that there is no copy/move of the
temporary `A{}`.
Clang prints on the other hand `A Amove ~A ~A `, which looks correct, because
of "no elision when initializing a base-class subobject", see
https://en.cppreference.com/w/cpp/language/copy_elision

Demo: https://gcc.godbolt.org/z/rafEsTdd9

  1   2   >