[Bug c++/103443] New: consteval function rejected as constant expression

2021-11-26 Thread vincent.hamp at higaski dot at via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103443

Bug ID: 103443
   Summary: consteval function rejected as constant expression
   Product: gcc
   Version: 11.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vincent.hamp at higaski dot at
  Target Milestone: ---

Not really sure whether that's a frontend or a libstdc++ bug, but GCC 11.1.0
(and according to godbolt trunk as well) does not accept the following snippet.


#include 
#include 
#include 

// #define QUALIFIER constexpr // compiles
#define QUALIFIER consteval// does not compile

template 
QUALIFIER uint32_t index_sequence2mask(std::index_sequence) {
if constexpr (sizeof...(Is) == 0u)
return 0u;
else
return ((1u << Is) | ...);
}

template {})>
void use_mask() {
printf("%s\n", __PRETTY_FUNCTION__);
}

int main() { use_mask(); }


The code is rejected with the following error:
"expression 'std::make_index_sequence<1>{}' is not a constant expression"

[Bug c++/99059] New: Static inline variable can't refer to itself

2021-02-10 Thread vincent.hamp at higaski dot at via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99059

Bug ID: 99059
   Summary: Static inline variable can't refer to itself
   Product: gcc
   Version: 11.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vincent.hamp at higaski dot at
  Target Milestone: ---

Declaring a static inline member variable and initializing it with a pointer to
itself is currently impossible. The textbook example for such code would
probably be a linked list of some sort:

struct link {
  link* next{nullptr};
  link* prev{nullptr};
};

struct list {
  static inline link tail{, };
};

list l;


Making the member just static and initializing it outside of the class works,
but this kinda breaks my mental model of "static inline" as just being
syntactic sugar. Is this an actual bug or just some overlooked thing in the
standard?

[Bug c++/95307] New: Compiler accepts reinterpret_cast in constexpr

2020-05-24 Thread vincent.hamp at higaski dot at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95307

Bug ID: 95307
   Summary: Compiler accepts reinterpret_cast in constexpr
   Product: gcc
   Version: 10.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vincent.hamp at higaski dot at
  Target Milestone: ---

The following snippet allows using reinterpret_casts inside a constexpr.

#include 
uint64_t v;
constexpr auto p{reinterpret_cast() - 1u};

Compiled with GCC 10.1 and 9.3 with -std=c++2a


Interestingly subtracting 0u results in an error.

[Bug c++/94422] New: static_cast from std::array to enum class

2020-03-31 Thread vincent.hamp at higaski dot at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94422

Bug ID: 94422
   Summary: static_cast from std::array to enum class
   Product: gcc
   Version: 9.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vincent.hamp at higaski dot at
  Target Milestone: ---

static_cast from std::array operator[] to an enum class inside a template class
produces an unexpected expression error. It seems that error is only present in
9.3, 9.2 and trunk work.

#include 
#include 

enum class EnumC : int8_t { Forward = 1, Backward = -1 };

std::array buf;

template 
struct S {
  void foo() { auto const cast_to_enum{static_cast(buf[0])}; }
};

S s;

[Bug c++/92134] New: static constinit members incorrectly compile

2019-10-17 Thread vincent.hamp at higaski dot at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92134

Bug ID: 92134
   Summary: static constinit members incorrectly compile
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vincent.hamp at higaski dot at
  Target Milestone: ---

The new C++20 constinit specifier currently doesn't seem to work with static
data members.

The following snippet compiles although the constructor of Value calls new.

struct Value {
  Value() : v{new int{42}} {}
  int* v;
};

struct S {
  static constinit inline Value v{};
};

int main() { return *S::v.v; }

[Bug c++/92003] New: constexpr-ness of char const* doesn't propagate

2019-10-05 Thread vincent.hamp at higaski dot at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92003

Bug ID: 92003
   Summary: constexpr-ness of char const* doesn't propagate
   Product: gcc
   Version: 9.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vincent.hamp at higaski dot at
  Target Milestone: ---

For some reasons the compiler seems to differ between a constexpr char const*
which is directly initialized by a string literal and one which actually points
to a constexpr char array.

The last expression in the following code-snippet fails to compile on the
current trunk:

constexpr char const* get_c_str() { return "abc"; }
constexpr bool use_get_c_str_in_constexpr_context{get_c_str()}; // works

template 
struct string {
  static constexpr char const* c_str() { return [0]; }

 private:
  static constexpr char c[]{Cs..., '\0'};
};

constexpr char const* cstr{string<'a', 'b', 'c'>::c_str()};
constexpr bool use_cstr_in_constexpr_context{cstr}; // doesn't work


https://godbolt.org/z/k3TBUC

[Bug c++/89871] New: Wall + designated initializers

2019-03-28 Thread vincent.hamp at higaski dot at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89871

Bug ID: 89871
   Summary: Wall + designated initializers
   Product: gcc
   Version: 8.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: vincent.hamp at higaski dot at
  Target Milestone: ---

Created attachment 46050
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46050=edit
Example fails to compile with -Wall

Using a struct with an anonymous union and trying to assign to it using
designated initializers does not compile with -Wall.

So e.g. 
g++ -std=c++2a -Wall designated_init.cpp

produces
"internal compiler error: side-effects element in no-side-effects CONSTRUCTOR"

The error can be reproduced on 8.1, 8.2 and 8.3. The current trunk however
seems to work.