[Bug c++/102678] New: GCC fails to compile immediately invoked lambda inside fold expression

2021-10-10 Thread michael.gerhold at web dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102678

Bug ID: 102678
   Summary: GCC fails to compile immediately invoked lambda inside
fold expression
   Product: gcc
   Version: 11.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: michael.gerhold at web dot de
  Target Milestone: ---

The following code

#include 
#include 
#include 

template
void printAlternatives([[maybe_unused]] const std::variant& variant)
{
([&]() {
// holds_alternative(variant); // <- enable to make it compile
T element{};
std::cout << element << "\n";
}(), ...);
}

int main() {
std::variant variant;
printAlternatives(variant);
}

does not compile and gives the following error message:

error: operand of fold expression has no unexpanded parameter packs

But the code does compile both on MSVC and Clang.

Live example on compiler explorer: https://godbolt.org/z/zEqW4njW3

[Bug sanitizer/118645] New: [UBSAN] UBSAN Fails on C-Style Arrays with constexpr User-Defined Destructors in GCC

2025-01-24 Thread michael.gerhold at web dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118645

Bug ID: 118645
   Summary: [UBSAN] UBSAN Fails on C-Style Arrays with constexpr
User-Defined Destructors in GCC
   Product: gcc
   Version: 14.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: sanitizer
  Assignee: unassigned at gcc dot gnu.org
  Reporter: michael.gerhold at web dot de
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
  Target Milestone: ---

Created attachment 60265
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60265&action=edit
preprocessed file

When creating a C-style array that contains elements whose type provides a
user-defined destructor, compilation fails if UBSAN is enabled.

Minimal example:
```
struct S {
constexpr S() = default;
constexpr ~S() { }
};

int main() {
static constexpr S array[10];
}
```

Compiler arguments: -std=c++20 -fsanitize=undefined

Error message:
```
: In function 'int main()':
:7:32: error: '(((const S*)(& array)) != 0)' is not a constant
expression
7 | static constexpr S array[10];
  |^
Compiler returned: 1
```

Compiler Explorer link: https://godbolt.org/z/897qMb1da

However, defining the destructor of `S` as `= default` works. Disabling UBSAN
also works.