Category "language-lawyer"

Compiler discrepencies in deduction of template parameter of nested alias template

Consider the following code snippet where we we're trying to deduce the template parameter to the function foobar(): struct Bar { static constexpr auto size =

Is placement new on a const variable with automatic storage duration legal? [duplicate]

Is the following code legal according to the standard? #include <new> int main() { const int x = 3; new ((void *)&x) int { 1

May a compiler store function-scoped, non-static, const arrays in constant data and avoid per-call initialization?

In reading How are char arrays / strings stored in binary files (C/C++)?, I was thinking about the various ways in which the raw string involved, "Nancy", would

Is most vexing parse a formally defined concept

I was reading an SO post where one user made the following comment: Also note that ArrTest<int> ar(); uses most vexing parse. But another user said the

Why does the use of `std::aligned_storage` allegedly cause UB due to it failing to "provide storage"?

Inspired by: Why is std::aligned_storage to be deprecated in C++23 and what to use instead? The linked proposal P1413R3 (that deprecates std::aligned_storage) s

C Pointer Arithmetic for Unusual Architectures

I'm trying to get a better understanding of the C standard. In particular I am interested in how pointer arithmetic might work in an implementation for an unusu

Is _Thread_local independent from __STDC_NO_THREADS__?

It seems that currently _Thread_local is independent from __STDC_NO_THREADS__. Consequence: even if an implementation defines __STDC_NO_THREADS__ to 1, then it

Why introduce `std::launder` rather than have the compiler take care of it?

I've just read What is the purpose of std::launder? and frankly, I am left scratching my head. Let's start with the second example in @NicolBolas' accepted answ

Ternary operator implicit cast to base class

Consider this piece of code: struct Base { int x; }; struct Bar : Base { int y; }; struct Foo : Base { int z; }; Bar* bar = new Bar; Foo* foo =

Why do std::stof, std::stod, and std::stold handle errors with exceptions?

What is the rationale for why std::stof, std::stod, and std::stold throw exceptions? http://en.cppreference.com/w/cpp/string/basic_string/stof Input errors are

Using setjmp and longjmp with a local jmp_buf

In the case that a local jmp_buf is actually represented by registers rather than stack memory, is it possible for setjmp or longjmp to cause the contents of th

Why does it matter if I use a method reference or a lambda here?

When I try to compile this code import java.util.Optional; public class GenericTest { public static void main(String[] args) { Optional.empty().m

C++ union struct with struct member works on Clang and MSVC but not GCC

I am trying to define a union struct with some struct and primitive members overlapping in memory with a simple array. This works perfectly in Clang and MSVC, b

Why is value-initialization specified as not calling trivial default constructors?

To value-initialize an object of type T means: ... — if T is a (possibly cv-qualified) class type without a user-provided or deleted default constructor,

Why are unqualified names from nondependent base classes favored over template parameters

The C++ standard says that unqualified names from nondependent base classes are preferred over template parameters. What is the reasoning behind this? The follo

Does a constructor has a "type" in C++ since it is a special member function

I recently learnt that constructors do not have names in C++ and some other things about them. I am also aware that a function has a type in C++ called a functi

Confusion about declaration and definition of static const data memebers

Scott Meyers writes in Effective Modern C++ (Item 30 page 210) that there's no need to define integral static const data members in classes; declarations alone

Can sizeof(size_t) be less than sizeof(int)?

Can sizeof(size_t) be less than sizeof(int)? Do the C and/or C++ standards guarantee that using unsigned int for array indexing is always safe?

Inheritance of copy constructors in C++17

Consider the following example: struct Parent { Parent (); Parent (const Parent &); }; struct Child : public Parent { using Parent::Parent; }