[Bug c++/85428] New: constexpr pointer equality comparison not considered constant expression

2018-04-17 Thread stinkingmadgod at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85428

Bug ID: 85428
   Summary: constexpr pointer equality comparison not considered
constant expression
   Product: gcc
   Version: 7.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: stinkingmadgod at gmail dot com
  Target Milestone: ---

The following should compile

template
struct S
{
inline static char c;
};

void foo()
{
constexpr auto t1 = &S::c;
constexpr auto t2 = &S::c;
static_assert(t1 != t2);
}

But won't, with error: non-constant condition for static assertion.

[expr.eq] says the pointers is specified to be unequal, and [expr.const] says
this is a constant expression.

However this compiles

inline char c1, c2;

void bar()
{
constexpr auto t1 = &c1;
constexpr auto t2 = &c2;
static_assert(t1 != t2);
}

Related is bug 70248 where the compiler accepts unspecified equality
comparisons as constant expressions when it shouldn't.

[Bug c++/86347] New: Incorrect call order of allocation function in new expression

2018-06-28 Thread stinkingmadgod at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86347

Bug ID: 86347
   Summary: Incorrect call order of allocation function in new
expression
   Product: gcc
   Version: 8.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: stinkingmadgod at gmail dot com
  Target Milestone: ---

As per [expr.new]/19 the statement new Type{expr}; should
1. call operator new
2. evaluate expr
3. initialize Type object

The example seems to suggest this isn't the case

struct Y
{
Y() { std::cout << "Y()\n"; }
Y(const Y&)
{
std::cout << "Y(const Y&)\n";
throw "tantrum"; 
}
};

struct X {
X(Y y) noexcept { }
};

int main()
{
try
{
[[maybe_unused]] Y y;
new X{y};
}
catch(...)
{

}
}

Should have output
new
Y()
Y(const Y&)

But has output
Y()
Y(const Y&)

Without the throw statement, it has output
Y()
Y(const Y&)
new

[Bug c++/86347] Incorrect call order of allocation function in new expression

2018-06-28 Thread stinkingmadgod at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86347

--- Comment #2 from stinkingmadgod at gmail dot com ---
Apologies, not familiar with netiquette here

#include
#include
#include

void* operator new(size_t n)
{
std::cout << "new\n";
return std::malloc(n);
}

struct Y
{
Y() { std::cout << "Y()\n"; }
Y(const Y&)
{
std::cout << "Y(const Y&)\n";
throw "tantrum"; 
}
};

struct X {
X(Y y) noexcept { }
};

int main()
{
try
{
[[maybe_unused]] Y y;
new X{y};
}
catch(...)
{

}
}

Online link: http://coliru.stacked-crooked.com/a/53fac07bba9fcb74

[Bug c++/92077] New: Multiple independent functions degrades optimizations

2019-10-12 Thread stinkingmadgod at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92077

Bug ID: 92077
   Summary: Multiple independent functions degrades optimizations
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: stinkingmadgod at gmail dot com
  Target Milestone: ---

#include

auto f()
{
std::string s1 = "abcdefg";
std::string s2 = "12345678";
return (s1 + s2).size();
}

#ifdef G
auto g()
{
std::string s1 = "abcdefg";
std::string s2 = "1234567";
return (s1 + s2).size();
}
#endif

Discovered on godbolt.org/z/6BTbMk, with target x86_64-linux-gnu built on
20191011. The definition of g() heavily influences assembly for f(). I assume
that this shouldn't happen in any case, hence the report.

AFAIK the optimization on f() is dependent on SSO.

g++ -std=c++2a -O2 gives:
f():
mov eax, 15
ret

g++ -std=c++2a -O2 -DG gives:
f():
pushr12
mov eax, 26213
pushrbp
pushrbx
sub rsp, 96
mov WORD PTR [rsp+20], ax
lea rbx, [rsp+16]
lea rbp, [rsp+48]
mov rsi, rsp
lea rdx, [rsp+32]
lea rdi, [rsp+64]
mov QWORD PTR [rsp], rbx
movabs  rax, 4050765991979987505
mov DWORD PTR [rsp+16], 1684234849
mov BYTE PTR [rsp+22], 103
mov QWORD PTR [rsp+8], 7
mov BYTE PTR [rsp+23], 0
mov QWORD PTR [rsp+32], rbp
mov QWORD PTR [rsp+48], rax
mov QWORD PTR [rsp+40], 8
mov BYTE PTR [rsp+56], 0
callstd::__cxx11::basic_string,
std::allocator > std::operator+,
std::allocator >(std::__cxx11::basic_string,
std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&)
mov rdi, QWORD PTR [rsp+64]
lea rax, [rsp+80]
mov r12, QWORD PTR [rsp+72]
cmp rdi, rax
je  .L69
mov rax, QWORD PTR [rsp+80]
lea rsi, [rax+1]
calloperator delete(void*, unsigned long)
.L69:
mov rdi, QWORD PTR [rsp+32]
cmp rdi, rbp
je  .L70
mov rax, QWORD PTR [rsp+48]
lea rsi, [rax+1]
calloperator delete(void*, unsigned long)
.L70:
mov rdi, QWORD PTR [rsp]
cmp rdi, rbx
je  .L68
mov rax, QWORD PTR [rsp+16]
lea rsi, [rax+1]
calloperator delete(void*, unsigned long)
.L68:
add rsp, 96
mov rax, r12
pop rbx
pop rbp
pop r12
ret
mov rbp, rax
jmp .L72

[Bug c++/41958] [c++0x] bogus variadic partial ordering code

2019-03-17 Thread stinkingmadgod at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41958

stinkingmadgod at gmail dot com changed:

   What|Removed |Added

 CC||stinkingmadgod at gmail dot com

--- Comment #11 from stinkingmadgod at gmail dot com ---
DR1395 made it in C++17.

template  int f(T*...);  // #1
template   int f(const T&); // #2
f((int*)0); // Should select #1 past C++17, should be ambiguous prior C++17.
// Selects #2 instead.

This is still the behaviour for trunk https://godbolt.org/z/ucAUHw

[Bug c++/86748] New: Terminates abnormally without error messages

2018-07-30 Thread stinkingmadgod at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86748

Bug ID: 86748
   Summary: Terminates abnormally without error messages
   Product: gcc
   Version: 7.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: stinkingmadgod at gmail dot com
  Target Milestone: ---

template 
struct flag
{
friend constexpr int adl_flag(flag);
};

template 
struct write
{
friend constexpr int adl_flag(flag) { return N; }
};

template {}))>
static constexpr int read(int, flag, int R = read(0, flag{}))
{
return R;
}

int main()
{
read(0, flag<0>{});
}

gcc version 7.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project) on
Windows 10

Compiled with

g++ main.cpp -std=c++17 -Wno-non-template-friend

Terminates after ~5x the usual compilation time and before completing (no
output) with no error messages. Memory usage goes to ~100MB during which.

I'm not certain if this is a bug, but given template instantiation depth
exceeded normally generates an error, clang segfaults and MSVC gives up, I
thought it might be worth reporting.

[Bug libstdc++/97561] New: coroutine_handle doesn't have inheritance

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

Bug ID: 97561
   Summary: coroutine_handle doesn't have inheritance
   Product: gcc
   Version: 11.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: stinkingmadgod at gmail dot com
  Target Milestone: ---

std::coroutine_handle doesn't inherit from
std::coroutine_handle.

[coroutine.handle.general]
template
struct coroutine_handle : coroutine_handle<>

#include
struct task {
struct promise_type {
task get_return_object() { return {}; }
std::suspend_never initial_suspend() { return {}; }
std::suspend_never final_suspend() { return {}; }
void return_void() {}
void unhandled_exception() {}
};
};

int main()
{
std::coroutine_handle c;
std::coroutine_handle<>& c2 = c;  // fails
}

[Bug libstdc++/97561] coroutine_handle doesn't have inheritance

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

--- Comment #3 from stinkingmadgod at gmail dot com ---
Thanks for the link.

I was attempting to create a type-erased task type where the handles in one
case was be passed in as a std::coroutine_handle<>& to avoid using
std::function and the like. It was experimental and unlikely to be motivating,
but I initially thought the inheritance situation was a bug.

[Bug libstdc++/97930] New: pair is not a structural type

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

Bug ID: 97930
   Summary: pair is not a structural type
   Product: gcc
   Version: 11.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: stinkingmadgod at gmail dot com
  Target Milestone: ---

template>
struct S;

This is valid in C++20, but fails due to libstdc++ using a private base
__pair_base, rendering pair non-structural.

[pairs.pairs]
pair is a structural type if T and U are both structural types.

[Bug c++/104179] New: Truncated representation of character arrays as non-type template parameters

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

Bug ID: 104179
   Summary: Truncated representation of character arrays as
non-type template parameters
   Product: gcc
   Version: 11.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: stinkingmadgod at gmail dot com
  Target Milestone: ---

#include

template
struct str
{
char data[N];
consteval str(const char (&arr)[N])
{
std::copy(arr, arr + N, data);
}
};

template
struct print;

constexpr char s[] = {'4', '2'};
print p;

Produces the error message

:17:10: error: aggregate 'print{"4"}> p' has incomplete type and
cannot be defined
   17 | print p;

Where print{"4"}> should be print{"42"}>
The intention is likely to print null-terminated strings correctly, as in

print<"42"> p2;

:16:13: error: aggregate 'print{"42"}> p2' has incomplete type
and cannot be defined
   16 | print<"42"> p2;