[Bug c++/105595] New: Coroutines can trigger -Wsubobject-linkage

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

Bug ID: 105595
   Summary: Coroutines can trigger -Wsubobject-linkage
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

To reproduce:
- Create a minimal coroutine promise
- Create a coroutine where any local's type has no linkage (for example a
lambda)
- #include the above from another, differently named, file

Result:
/app/not_example.cpp:25:1: warning: 'foo()::_Z3foov.Frame' has a field
'foo()::_Z3foov.Frame::anon_ns_1_2' whose type uses the anonymous namespace
[-Wsubobject-linkage]
/app/not_example.cpp:25:1: warning: 'foo()::_Z3foov.Frame' has a field
'foo()::_Z3foov.Frame::inner_class_1_2' whose type has no linkage
[-Wsubobject-linkage]
/app/not_example.cpp:25:1: warning: 'foo()::_Z3foov.Frame' has a field
'foo()::_Z3foov.Frame::a_lambda_1_2' whose type has no linkage
[-Wsubobject-linkage]

Expected:
No warning, because the coroutine frame's type shouldn't have linkage either.
Sticking anonymous types inside each other is harmless.

Full testcase:


# 2 "/app/not_example.cpp" 1

#include 

class async {
public:
class promise_type {
public:
async get_return_object() { return {}; }
std::suspend_never initial_suspend() { return {}; }
std::suspend_never final_suspend() noexcept { return {}; }
void unhandled_exception() {}
};
};

namespace {
class anon_ns_t {};
}

async foo()
{
anon_ns_t anon_ns;
class inner_class_t {} inner_class;
auto a_lambda = [](){};
co_await std::suspend_never{};
}


Compile with -std=c++20.

Compiler Explorer: https://godbolt.org/z/efz6dfoWq

[Bug c++/97221] New: Returning an array unexpectedly favors const overload in return value's constructor

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

Bug ID: 97221
   Summary: Returning an array unexpectedly favors const overload
in return value's constructor
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

struct string {
const char * m;
template string(const char (&str)[N]) { m = "CONST"; }
template string(char (&str)[N]) { m = "MUT"; }
};

string foo()
{
char bar[8];
return bar;
}

With Clang 10.0.1 -O2 -std=c++11, this returns "MUT".
With GCC 10.2 -O2 -std=c++98, this returns "MUT".
With GCC 7.5 -O2 -std=c++11, this returns "MUT".
With GCC 10.2 -O2 -std=c++11, this returns "CONST".

This one should give same result for every configuration, or at least throw a
warning from -Wc++11-compat, right?

Compiler Explorer: https://godbolt.org/z/r3Yo64

(Context: I encountered this when trying to make my string class distinguish
between string literals and char arrays/pointers, and call sizeof instead of
strlen for the former.)

[Bug c++/91212] [8/9/10/11 Regression] const ignored for ctor arguments within return since r8-2493-g4ce8c5dea53d8073

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

Alfred Agrell  changed:

   What|Removed |Added

 CC||blubban at gmail dot com

--- Comment #10 from Alfred Agrell  ---
*** Bug 97221 has been marked as a duplicate of this bug. ***

[Bug c++/97221] Returning an array unexpectedly favors const overload in return value's constructor

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

Alfred Agrell  changed:

   What|Removed |Added

 Resolution|--- |DUPLICATE
 Status|UNCONFIRMED |RESOLVED

--- Comment #2 from Alfred Agrell  ---
Ah, indeed it is. I should've checked gcc-trunk on CE, I keep forgetting it
exists. Thanks, and sorry for the noise.

*** This bug has been marked as a duplicate of bug 91212 ***

[Bug other/97280] New: Documentation typo - 'roudnevenl'

2020-10-03 Thread blubban at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97280

Bug ID: 97280
   Summary: Documentation typo - 'roudnevenl'
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: other
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html

"Outside strict ISO C mode [...], the functions [...] roundeven, roundevenf,
roudnevenl, scalbf [...]"

Should be roundevenl. It's a documentation bug only, GCC itself implements the
expected name.

[Bug c++/103825] New: [12 Regression] ICE on switch on enum class in bitfield

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

Bug ID: 103825
   Summary: [12 Regression] ICE on switch on enum class in
bitfield
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

enum class Type { Pawn };
struct Piece {
  Type type : 4;
};
void foo() {
  switch (Piece().type)
case Type::Pawn:;
}


The above causes an ICE on GCC 12.0.0 20211222, no compile flags needed. It
compiles without warnings on GCC 11, Clang, and MSVC.

Compiler Explorer: https://godbolt.org/z/GdG6ovEzz


: In function 'void foo()':
:5:6: error: type precision mismatch in switch statement
5 | void foo() {
  |  ^~~
switch (retval.0) , case 0: >
:5:6: internal compiler error: 'verify_gimple' failed
0x2115089 internal_error(char const*, ...)
???:0
0x11603ed verify_gimple_in_seq(gimple*)
???:0
0xdda0d1 gimplify_body(tree_node*, bool)
???:0
0xdda397 gimplify_function_tree(tree_node*)
???:0
0xbe6a57 cgraph_node::analyze()
???:0
0xbeaf6d symbol_table::finalize_compilation_unit()
???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.

[Bug web/103877] New: libstdc++ docs give a bad recommendation for printing C++ defines

2021-12-31 Thread blubban at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103877

Bug ID: 103877
   Summary: libstdc++ docs give a bad recommendation for printing
C++ defines
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: web
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

https://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.predefined

> You can also run g++ -E -dM - < /dev/null" to display a
> list of predefined macros for any particular installation.

Issue 1: The unmatched quote.

Issue 2: g++ -E defaults to C mode, where _GNU_SOURCE is, in fact, not defined.
The correct command is  g++ -E -dM -xc++ - < /dev/null

[Bug libstdc++/103911] New: std::from_chars shouldn't call isdigit

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

Bug ID: 103911
   Summary: std::from_chars shouldn't call isdigit
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

In header , function __from_chars_alnum calls std::isdigit().

In addition to looking weird ("everyone" knows ctype is locale dependent and
charconv is not), this can cause trouble in a handful of rare cases.

If another thread concurrently calls setlocale, that's a race condition;
additionally, if the locale contains digits other than '0'..'9', from_chars can
return wrong answer. (For example, some versions of Windows libc think 0xB2,
0xB3 and 0xB9 are the digits ²³¹ in the "us" locale.)

GCC will, by default, replace isdigit with c>='0' && c<='9'; to reproduce the
above, use -fno-builtin or Clang.

(Bonus issue: A comment on that function says it applies to bases 11 to 26.
Shouldn't that be 11 to 36?)

[Bug c++/107151] New: Specializing a concepted template can emit bogus assembly

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

Bug ID: 107151
   Summary: Specializing a concepted template can emit bogus
assembly
   Product: gcc
   Version: 13.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

#include 
#include 

template 
void fun(T);

template <>
void fun(char c)
{
std::puts("foo()");
}

template 
void fun(I i)
{
std::puts("foo()");
}

int main()
{
fun(' ');
}

Compile with -std=c++20.

Result:
/tmp/cctfBAWi.s: Assembler messages:
/tmp/cctfBAWi.s:63: Error: symbol `_Z3funIcEvT_' is already defined
/tmp/cctfBAWi.s: Error: .size expression for _Z3funIcEvT_ does not evaluate to
a constant

Expected: Prints foo(), or at least a less cryptic error. With -O2, GCC
only emits one _Z3funIcEvT_, but the resulting program prints
foo().

https://godbolt.org/z/axvdbK1Eh

Clang and MSVC have similar bugs:
https://github.com/llvm/llvm-project/issues/58142
https://developercommunity.visualstudio.com/t/Template-explicit-specializationconcept/10012835

[Bug c++/107913] New: Bogus unused variable warning if used in if constexpr false in lambda with default capture by ref

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

Bug ID: 107913
   Summary: Bogus unused variable warning if used in if constexpr
false in lambda with default capture by ref
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

template
int b()
{
constexpr int c = 123;
constexpr int d = 456;

return [&](){
if constexpr (a)
return c;
else
return d;
}();
}

int g() { return b(); }
int h() { return b(); }


Compile with -Wall.

Expected result: No warnings.

Actual result:

: In instantiation of 'int b() [with bool a = true]':
:15:25:   required from here
:5:19: warning: variable 'd' set but not used
[-Wunused-but-set-variable]
5 | constexpr int d = 456;
  |   ^
: In instantiation of 'int b() [with bool a = false]':
:16:26:   required from here
:4:19: warning: variable 'c' set but not used
[-Wunused-but-set-variable]
4 | constexpr int c = 123;
  |   ^


The warning is very fragile, and goes away if (pick one or more)
- either variable is changed to not constexpr (oddly enough, both warnings
disappear if either variable is not constexpr)
- either variable is changed to static
- the if is changed to not constexpr
- the lambda is removed
- the variables are captured explicitly
- the lambda's default capture is by-value
(The bug does reproduce if the template is removed and changed to if constexpr
(true), but I feel the current form better demonstrates that the warning is
inappropriate.)

https://godbolt.org/z/T9nnzjj91

[Bug c++/103871] [11/12/13 Regression] co_await causes build error

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

Alfred Agrell  changed:

   What|Removed |Added

 CC||blubban at gmail dot com

--- Comment #15 from Alfred Agrell  ---
Just ran into this (and/or bug 98056). Still exists as of trunk-20220522.
Minimized to https://godbolt.org/z/qhWWzKe4M


#include 
#include 

class my_coro {
public:
my_coro();
class promise_type {
public:
my_coro get_return_object();
std::suspend_never initial_suspend();
std::suspend_never final_suspend() noexcept;
void unhandled_exception();
};
};

std::suspend_never inner(std::initializer_list);

my_coro doesnt_work()
{
co_await inner({ 1,2,3 });
}

[Bug c++/105804] New: List-initialized argument in await expression is doubly freed

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

Bug ID: 105804
   Summary: List-initialized argument in await expression is
doubly freed
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

#include 
#include 

struct my_params {
std::unique_ptr ptr; // or any other object with nontrivial dtor
};

static std::suspend_never take_params(my_params params)
{
return {};
}

struct coro_t {
struct promise_type {
coro_t get_return_object() { return {}; }
std::suspend_never initial_suspend() { return {}; }
std::suspend_never final_suspend() noexcept { return {}; }
void unhandled_exception() noexcept {}
};
};

static coro_t my_coro()
{
co_await take_params({ std::make_unique(5) });
}

int main()
{
my_coro();
}


Expected output: Same as /bin/true
Actual: free(): double free detected in tcache 2

https://godbolt.org/z/8f9d3TzYo

Probably same root cause as bug 98056 and/or bug 103871, but since the symptoms
are way different (it's a wrong-code, not just rejects-valid), I think it
warrants a separate report.

[Bug c++/106541] New: Missing -Wuninitialized on self initialization if external code is called earlier in the function

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

Bug ID: 106541
   Summary: Missing -Wuninitialized on self initialization if
external code is called earlier in the function
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

struct my_class {
int data[4];
};

void fn1();

void fn2()
{
my_class local = local;
}

void fn3()
{
fn1();
my_class local = local;
}


Compile with g++ -Wall.

Expected: Two warnings. Or maybe zero, if this is not considered a use.

Actual: Former complains, latter does not. That extra function call should not
affect the warning count.

https://godbolt.org/z/vhdnq1Ec1

[Bug sanitizer/101758] New: Inconsistent optimizations with UBSan

2021-08-03 Thread blubban at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101758

Bug ID: 101758
   Summary: Inconsistent optimizations with UBSan
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: sanitizer
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at 
gcc dot gnu.org
  Target Milestone: ---

Input:

gcc -fsanitize=undefined -O2 -fno-strict-aliasing -Wall

float b(unsigned a) { return *(float*)&a; }
float c(unsigned a) { return *(float*)&a; }
float d(unsigned a) { return *(float*)&a; }


Output:

b:
mov DWORD PTR [rsp-4], edi
movss   xmm0, DWORD PTR [rsp-4]
ret
c:
movdxmm0, edi
ret
d:
movdxmm0, edi
ret

or, on ARM

b:
sub sp, sp, #8
str r0, [sp, #4]
vldr.32 s0, [sp, #4]
add sp, sp, #8
bx  lr
c:
sub sp, sp, #8
vmovs0, r0
add sp, sp, #8
bx  lr
d:
sub sp, sp, #8
vmovs0, r0
add sp, sp, #8
bx  lr


Expected output:

Same assembly for all three. And maybe don't set up an unused stack frame on
ARM (it's correctly optimized out without UBSan).


Compiler Explorer: https://godbolt.org/z/Tfs5qazqM


(Found it while trying to determine if that function is a strict aliasing
violation (it is), and whether it can be fixed with memcpy or a union (both
work).)

[Bug c++/102120] New: expected tree that contains 'decl common' structure, have 'identifier_node' in dump_aggr_type, at cp/error.c:786

2021-08-29 Thread blubban at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102120

Bug ID: 102120
   Summary: expected tree that contains 'decl common' structure,
have 'identifier_node' in dump_aggr_type, at
cp/error.c:786
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

Input:


union U {
int value;
constexpr ~U() noexcept { }
};

constexpr int z() {
U* array = new U[5];
int result = array[3].value;
delete[] array;
return result;
}

constexpr int zz = z();


Compile with -std=c++20.

Expected output (I get this if I remove the union's dtor, or change the array
to a single object):


:13:21:   in 'constexpr' expansion of 'z()'
:13:22: error: the content of uninitialized storage is not usable in a
constant expression
   13 | constexpr int zz = z();
  |  ^
:7:23: note: allocated here
7 | U* array = new U[5];
  |   ^


Actual output on GCC 11.2:


'
:13: confused by earlier errors, bailing out


Yes, those two lines are the entirety of its output.

GCC trunk is slightly better, but still asks for a bug report:


'
:13:21:   in 'constexpr' expansion of 'z()'
tree check: expected tree that contains 'decl common' structure, have
'identifier_node' in dump_aggr_type, at cp/error.c:786
   13 | constexpr int zz = z();
  |  ^
0x1f30289 internal_error(char const*, ...)
???:0
0x6bb645 tree_contains_struct_check_failed(tree_node const*,
tree_node_structure_enum, char const*, int, char const*)
???:0
0x1f4c781 pp_format(pretty_printer*, text_info*)
???:0
0x1f2eeb5 diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
???:0
0x1f2fde9 error(char const*, ...)
???:0
0xae3d0a store_init_value(tree_node*, tree_node*, vec**, int)
???:0
0x89b0c9 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
???:0
0x9d09a5 c_parse_file()
???:0
0xb55af2 c_common_parse_file()
???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.


Compiler Explorer: https://godbolt.org/z/WETs8jbMG

Posted by user konstantinua00 on the Compiler Explorer Discord, who may or may
not have found it via someone else.

[Bug c++/102198] New: Unused and nonsensical template instantiations used for return type inference end up in the output

2021-09-03 Thread blubban at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102198

Bug ID: 102198
   Summary: Unused and nonsensical template instantiations used
for return type inference end up in the output
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

Input:

template
int* a() { return x; }

template
auto b() { return a; }

template
auto c() -> int* (*)()
{
static int x1;
return b<&x1>();
}

int main(int argc, char** argv)
{
if constexpr (false)
{
static int x2;
b<&x2>();
}
c();
c();
}

Compile with -O0.

Expected output: Compiles and links successfully.

Actual output, as of 7.2 through 11.2: Assembly output contains four
instantiations of a(), using template arguments c::x1, c::x1,
main::x2, and c::x1 (or whatever _ZZ1cIXT_EEPFPivEvE2x1 is
supposed to be, c++filt doesn't like it). There's no storage assigned for the
latter two, so they instantiations throw linker errors.

/opt/compiler-explorer/gcc-11.2.0/bin/../lib/gcc/x86_64-linux-gnu/11.2.0/../../../../x86_64-linux-gnu/bin/ld:
/tmp/cc2i7eNg.o: in function `_Z1aIXadL_ZZ1cIXT_EEPFPivEvE2x1EEES1_v':
:2: undefined reference to `_ZZ1cIXT_EEPFPivEvE2x1'
/opt/compiler-explorer/gcc-11.2.0/bin/../lib/gcc/x86_64-linux-gnu/11.2.0/../../../../x86_64-linux-gnu/bin/ld:
/tmp/cc2i7eNg.o: in function `int* a<&(main::x2)>()':
:2: undefined reference to `main::x2'
collect2: error: ld returned 1 exit status

Actual output, as of current trunk:

: In instantiation of 'auto b() [with int* x = (& x1)]':
:5:6:   required from here
:5:6: internal compiler error: in discriminator_for_local_entity, at
cp/mangle.c:1965
5 | auto b() { return a; }
  |  ^
0x1f31a39 internal_error(char const*, ...)
???:0
0x79e1c7 fancy_abort(char const*, int, char const*)
???:0
0x8fe32b mangle_decl(tree_node*)
???:0
0x148f6b2 decl_assembler_name(tree_node*)
???:0
0x14c15d0 assign_assembler_name_if_needed(tree_node*)
???:0
0xc38855 cgraph_node::analyze()
???:0
0xc3cfdd symbol_table::finalize_compilation_unit()
???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.

The issues go away if I change main to  if constexpr (true)  or remove the
template from c(), if I put x1 and x2 in global scope, if I append  -> int*
(*)()  to b(), or if I enable -O1 or higher. Only the template variant gives
ICE,  if constexpr (false)  gives the same bad output in trunk as in 11.2
(after removing or neutralizing c()).

I don't know how many different issues this is, but they all look like
different facets of the same root cause (either the extra a() instantiations
should be discarded after determining b's return type, or they shouldn't be
created at all), so I'm filing one bug for them all.

Compiler Explorer: https://godbolt.org/z/89794xb8v

[Bug c++/105804] coroutines: List-initialized argument in await expression is doubly freed

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

Alfred Agrell  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |FIXED

--- Comment #1 from Alfred Agrell  ---
Looks like this one was fixed at some point. Probably by commit
r13-6702-gea4dd8f512979db247c54d6b41377bb73699bcd7, as reported in bug 103871.

Good job, GCC team.

[Bug c++/114167] New: Capturing a auto..., then unpacking it in a lambda taking Ts..., confuses GCC

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

Bug ID: 114167
   Summary: Capturing a auto..., then unpacking it in a lambda
taking Ts..., confuses GCC
   Product: gcc
   Version: 13.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

void a(int, int) {}

template
void b()
{
[](auto... ch){
[ch...](Ts... newvals) {
(a(ch, newvals), ...);
}(3,4);
}(1,2);
}

void c()
{
b();
}


No flags needed. (Needs -std=c++17, but that's the default.)

Expected: Should compile.

Actual:


: In instantiation of 'a():: [with auto:1
= {int, int}]':
:8:6:   required from 'void a() [with Ts = {int, int}]'
:13:15:   required from here
:6:19: error: 'newvals#0' is not captured
6 | ((ch, newvals), ...);
  |   ^~~
:5:9: note: the lambda has no capture-default
5 | [ch...](Ts... newvals) {
  | ^~~~
6 | ((ch, newvals), ...);
  | ~
7 | }(3,4);
  | ~
:5:19: note: 'int newvals#0' declared here
5 | [ch...](Ts... newvals) {
  | ~~^~~
Compiler returned: 1


I'm not 100% sure if that is valid C++, but Clang accepts it, and the error
message somehow manages to ask to capture newvals before it's declared.

https://godbolt.org/z/G8Kh9rvYc

[Bug target/107337] -march docs for nocona are missing CX16

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

Alfred Agrell  changed:

   What|Removed |Added

 CC||blubban at gmail dot com

--- Comment #3 from Alfred Agrell  ---
This bug still exists. In addition to nocona, it also affects bonnell,
sierraforest, grandridge, clearwaterforest, alderlake, arrowlake, arrowlake-s,
pantherlake, and amdfam10 aka barcelona.

[Bug c++/115318] New: decltype(lambda) with some templates causes ICE

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

Bug ID: 115318
   Summary: decltype(lambda) with some templates causes ICE
   Product: gcc
   Version: 14.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

template struct S {};

template
void foo()
{
using foo_t = decltype([](){});
[]() { S{}; }();
}

void bar() { foo(); }


-std=c++20


: In instantiation of 'foo<>():: [with int k = 6]':
:7:36:   required from 'void foo() [with int i = 4]'
7 | []() { S{}; }();
  | ~~~^~
:10:17:   required from here
   10 | void bar() { foo(); }
  |  ~~~^~
:6:28: internal compiler error: in tsubst, at cp/pt.cc:16401
6 | using foo_t = decltype([](){});
  |^~
0x202ef4c internal_error(char const*, ...)
???:0
0x778915 fancy_abort(char const*, int, char const*)
???:0
0x938dd0 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0x943a11 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
???:0
0x939200 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0x93c437 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
???:0
0x931a0f instantiate_decl(tree_node*, bool, bool)
???:0
0x831fb7 maybe_instantiate_decl(tree_node*)
???:0
0x8332f7 mark_used(tree_node*, int)
???:0
0x7a20a3 build_op_call(tree_node*, vec**, int)
???:0
0x9602fe finish_call_expr(tree_node*, vec**, bool,
bool, int)
???:0
0x931a0f instantiate_decl(tree_node*, bool, bool)
???:0
0x94d2e3 instantiate_pending_templates(int)
???:0
0x835608 c_parse_final_cleanups()
???:0
0xa0c508 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.
Compiler returned: 1


If you make the first lambda a template ( decltype([](){}) ), you'll get a
internal compiler error: Segmentation fault instead. Probably the same root
cause.


Online reproducer: https://godbolt.org/z/EfxPxKWhd


I tried searching for duplicates, but every open issue I could find in bug
#107430 is a mess, I can't determine if it's the same.

[Bug c++/115319] New: ICE when mutating a captured parameter in an explicit-this lambda if a capture is not trivially copyable

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

Bug ID: 115319
   Summary: ICE when mutating a captured parameter in an
explicit-this lambda if a capture is not trivially
copyable
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

struct S
{
S() {}
S(const S&) {}
};

void a()
{
[i=0, x=S{}](this auto self) -> void
{
i++;
}();
}


-std=c++23 (optional, it throws a c++23-extensions warning and the same ICE
without it)


: In lambda function:
:11:9: internal compiler error: in gimplify_compound_lval, at
gimplify.cc:3576
   11 | i++;
  | ^
0x202ef4c internal_error(char const*, ...)
???:0
0x778915 fancy_abort(char const*, int, char const*)
???:0
0xc4c739 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0xc55a00 gimplify_self_mod_expr(tree_node**, gimple**, gimple**, bool,
tree_node*)
???:0
0xc4cf52 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0xc4e8c4 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0xc4ca8d gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0xc4e8ae gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0xc50e8e gimplify_body(tree_node*, bool)
???:0
0xc51250 gimplify_function_tree(tree_node*)
???:0
0xaba647 cgraph_node::analyze()
???:0
0xabd9b1 symbol_table::finalize_compilation_unit()
???: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.
Compiler returned: 1


Online reproducer: https://godbolt.org/z/Go6YdPTME


It seems that the explicit this makes by-value captures mutable, so I think
this is an ice-on-valid, but that is a pretty odd-sounding rule, so I'm not
entirely sure.


(one of my friends just discovered that posting GCC ICEs where I see them gets
them reduced and reported. Said friend claims to encounter like billions of
ICEs every day, so I may end up submitting a lot of ICEs and other gcc bugs in
the near future. I'll make sure to reduce every testcase, validate that it is a
bug, and try to find existing reports, of course)

[Bug c++/115331] New: [15 regression] ICE-on-invalid passing a typoed lambda to a list-initializer

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

Bug ID: 115331
   Summary: [15 regression] ICE-on-invalid passing a typoed lambda
to a list-initializer
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

struct has_ctor
{
has_ctor(auto arg) {}
};

void aaa()
{
has_ctor{[]<(){}}; // typo intentional
}


-std=c++20


: In function 'void aaa()':
:8:17: error: expected identifier before '(' token
8 | has_ctor{[]<(){}};
  | ^
:8:19: error: expected '>' before '{' token
8 | has_ctor{[]<(){}};
  |   ^
: In instantiation of 'has_ctor::has_ctor(auto:1) [with auto:1 =
aaa()::]':
:3:5:   required from here
3 | has_ctor(auto arg) {}
  | ^~~~
:3:5: internal compiler error: tree check: expected tree that contains
'decl common' structure, have 'error_mark' in decl_template_parm_check, at
cp/cp-tree.h:5138
0x269996c internal_error(char const*, ...)
???:0
0x96eb0f tree_contains_struct_check_failed(tree_node const*,
tree_node_structure_enum, char const*, int, char const*)
???:0
0xba20c6 mangle_decl(tree_node*)
???:0
0x16c5fc5 decl_assembler_name(tree_node*)
???:0
0x16eea01 assign_assembler_name_if_needed(tree_node*)
???:0
0xe8c11d cgraph_node::analyze()
???:0
0xe8f6d1 symbol_table::finalize_compilation_unit()
???: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.
Compiler returned: 1


Online reproducer: https://godbolt.org/z/K1hjEsaf5


The ICE does not reproduce on 14.1, it's trunk only (tested on
Compiler-Explorer-Build-gcc-cbf2ed4b309d54039d74be5d730299012e7681b3-binutils-2.42,
15.0.0 20240603).

[Bug c++/115364] New: ICE-on-invalid when calling non-const template member on const object

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

Bug ID: 115364
   Summary: ICE-on-invalid when calling non-const template member
on const object
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

struct foo
{
template void not_const() {}
};
void fn(const foo& obj) { obj.not_const<5>(); }


No flags needed.


: In member function 'void foo::fn() const':
:4:41: error: cannot convert 'const foo*' to 'foo*'
4 | void fn() const { this->not_const<5>(); }
  |   ~~^~
:4:41: internal compiler error: tree check: expected function_decl,
have template_decl in get_fndecl_argument_location, at cp/call.cc:8354
0x26aa1ac internal_error(char const*, ...)
???:0
0x96fd9e tree_check_failed(tree_node const*, char const*, int, char const*,
...)
???:0
0xa7d15f complain_about_bad_argument(unsigned int, tree_node*, tree_node*,
tree_node*, int)
???:0
0xa8c20a build_new_method_call(tree_node*, tree_node*, vec**, tree_node*, int, tree_node**, int)
???:0
0xce8267 finish_call_expr(tree_node*, vec**, bool,
bool, int)
???:0
0xc6a70a c_parse_file()
???:0
0xdbfcf9 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.
Compiler returned: 1


Online reproducer: https://godbolt.org/z/86noE3935


I would've expected something as simple as this to have been tested and fixed
long ago, but apparently not. Probably because it's just a tree check; from
what I've heard, they don't exist in versioned releases of GCC.

[Bug tree-optimization/115423] New: Inlined strcmp optimizes poorly

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

Bug ID: 115423
   Summary: Inlined strcmp optimizes poorly
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

bool g(const char* c) {
return __builtin_strcmp(c, ".") == 0 ||
   __builtin_strcmp(c, "..") == 0;
}
bool h(const char* c) {
return (c[0] == '.' && c[1] == '\0') ||
   (c[0] == '.' && c[1] == '.' && c[2] == '\0');
}


Compile with -O2.


Expected result: Same output from both.

Actual: The former results in a mess that, among other inefficiencies, loads
c[0] twice.


Online reproducer: https://godbolt.org/z/E4vEshvcM


(I don't know if this is an RTL or tree optimizer issue, I just guessed. Feel
free to move it if it's wrong.)

[Bug tree-optimization/115423] Inlined strcmp optimizes poorly

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

--- Comment #3 from Alfred Agrell  ---
strcmp (c, "ABCDEFGHabcdefgh") || strcmp (c, "ABCDEFGHfoobar") can safely be
optimized to 1, you're thinking of strcmp(c, "ABCDEFGHabcdefgh")==0 ||
strcmp(c, "ABCDEFGHfoobar")==0.

Optimizing to multi-byte reads would be a wrong-code. If strcmp(c, "1234567")
does an eight-byte read, it'll segfault if c is {'e',0} four bytes before an
unmapped page.

Even if limiting it to aligned reads (can't segfault without crossing a page),
it'll annoy Valgrind.

(Large reads would be safe if lhs is char[8] and not char*, or if strlen is
checked before doing those reads, but both of those feel unlikely to me.)

[Bug c++/115318] decltype(lambda) from an template function inside a templated lambda causes ICE

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

--- Comment #2 from Alfred Agrell  ---
struct a { int c; };

template
struct ddd {
int f()
{
using a2 = decltype([](int a::*)->a{}(&a::c));
return [](int a2::*){ return 2; }(&a::c);
}
};

int xs() { return ddd().f(); }


-std=c++20 again


-> :8:16: sorry, unimplemented: mangling offset_ref


https://godbolt.org/z/4M3ToqqPW


Adding a  to the first lambda changes the error to the same ICE as this
issue (https://godbolt.org/z/Pq9T16GvP), so I'm about 98% sure it's the same
root cause.

[Bug c++/105667] [C++20] lambas in template argument sometimes causes an ICE (seg fault)

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

Alfred Agrell  changed:

   What|Removed |Added

 CC||blubban at gmail dot com

--- Comment #8 from Alfred Agrell  ---
I ran into something similar. My reduced testcase is


struct class1
{
virtual void a_function() = 0;
};

template() {}>
class class2 {};

template
struct class3 : public class1 {
void a_function()
{
class2<> x;
}
};

struct class4 : public class3 {
class4() {}
};


https://godbolt.org/z/GKo5oWe8j

[Bug c++/110565] New: Incomplete note on why initializing int& with int is ill-formed

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

Bug ID: 110565
   Summary: Incomplete note on why initializing int& with int is
ill-formed
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

struct X {
X(int&);
X(X&&) = delete; // the issue reproduces without this line, but the error
is clearer with it
};

template
void f() {
new X(0);
}


Expected output:

: In function 'void f()':
:8:12: error: no matching function for call to 'X::X(int)'
8 | new X(0);
  |^
:2:5: note: candidate: 'X::X(int&)' (near match)
2 | X(int&);
  | ^
:2:5: note:   conversion of argument 1 would be ill-formed:
:8:11: error: cannot bind non-const lvalue reference of type 'int&' to
an rvalue of type 'int'


Actual output:

: In function 'void f()':
:8:12: error: no matching function for call to 'X::X(int)'
8 | new X(0);
  |^
:2:5: note: candidate: 'X::X(int&)' (near match)
2 | X(int&);
  | ^
:2:5: note:   conversion of argument 1 would be ill-formed:


The template and new-expression are necessary; the error is proper without
them.

https://godbolt.org/z/c1Er5nsjd

[Bug libstdc++/112564] New: std::format(std::thread::id) is incorrectly left-aligned

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

Bug ID: 112564
   Summary: std::format(std::thread::id) is incorrectly
left-aligned
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/zra9GddY3

N4964 [thread.thread.id]/12 "If the align option is omitted it defaults to >."
Both MSVC and libc++ right-align thread::id here as mandated by that paragraph,
but libstdc++ is left-aligning.

I am not sure how duration should be aligned by default but either libstdc++ or
libc++ are buggy here.


Found by https://github.com/StephanTLavavej

[Bug c++/116584] New: Type/value mismatch confuses error recovery

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

Bug ID: 116584
   Summary: Type/value mismatch confuses error recovery
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: blubban at gmail dot com
  Target Milestone: ---

template struct foo;

void* bar()
{
return (decltype(foo<5>)*)5;
}


No flags needed.


Result:

: In function 'void* bar()':
:5:31: error: type/value mismatch at argument 1 in template parameter
list for 'template struct foo'
5 | return (decltype(foo<5>)*)5;
  |   ^
:5:31: note:   expected a type, got '5'
:5:17: error: expected primary-expression before 'decltype'
5 | return (decltype(foo<5>)*)5;
  | ^~~~
:5:17: error: expected ')' before 'decltype'
5 | return (decltype(foo<5>)*)5;
  |~^~~~
  | )
Compiler returned: 1


Expected: Just the first error, the last one looks like it's telling me to
write  return ();

Diagnostics are even funnier if colored - in the last one, the first letter of
decltype is red, while the ecltype is green. https://godbolt.org/z/7bcazrPsY