Category "language-lawyer"

In Rust, what happens if main function returns Err?

According to The Rust Reference, If a main function is present, (snip), and its return type must be one of the following: () Result<(), E> where E: Erro

Ternary operator applied to class with conversion operator and delete constructor causes ambiguity

struct A { A(); A(int) = delete; operator int(); }; int main() { true ? A{} : 0; } Compile with C++20, Clang accepts it, but GCC and MSVC reject it w

Is #include "filename.hpp" actually an undefined behavior?

The C++20 standard states the following about source file inclusion: 15.3:5 (page 437): The implementation shall provide unique mappings for sequences consisti

Type conflicts in non-type template argument deduction

#include<type_traits> template <typename T, T> struct A { }; template <typename T, T t> void f(A<T, t>) { } int main() { f(A<c

Why the unary * operator does not have a constraint "the operand shall not be a pointer to void"?

C2x, 6.5.3.2 Address and indirection operators, Constraints, 2: The operand of the unary * operator shall have pointer type. Why there is no constraint "the o

What is the rationale for "structure with flexible array member shall not be a member of a structure"?

C11, 6.7.2.1 Structure and union specifiers, Constraints, 3 (emphasis added): A structure or union shall not contain a member with incomplete or function type

Why isn't an IEC 60559 conformant implementation required to define __STDC_IEC_559__ (to 1)?

The C (C99+) standard requires (though implicitly) a conforming implementation to define __STDC__ to 1. However, the C standard does not require an IEC 60559 co

Template partial ordering - why does partial deduction succeed here

Consider the following simple (to the extent that template questions ever are) example: #include <iostream> template <typename T> struct identity;

Initialize array based on C++ version and compiler

In C++11 or higher regardless of compiler int myArray[10] = { 0 }; would initialize to all elements to zero. The question is would this also work in C++98 and c

Why would one format date in logs using "%c"?

A widely used piece of code sets the default datefmt in logging.Formatter to "%a %b %d %H:%M:%S %Y %Z" (same as "%c" in C locale). The code was written 12+ year

Dynamically allocated structures are well initialised?

For POD structure, could new Demo_Class[CONST_NUMBER]() guarantee the dynamically allocated structures are well initialised(i.e. not garbage) in C++11 and after

Can floats not suport negative or even 0?

It's follow-up question to: How to detect non IEEE-754 float, and how to use them? In theory, can we assume that c float always support negative numbers?

Does i = x[i]++; lead to undefined behavior?

Can someone please explain whether i = x[i]++; lead to undefined behavior? Note: x[i] and i are not both volatile and x[i] does not overlap i. There is C11, 6.5

Why does C++'s "using namespace" work the way it does?

All students are surprised by the behavior of C++ using-directives. Consider this snippet (Godbolt): namespace NA { int foo(Zoo::Lion); } namespace NB {

Calling `std::vector<A>::data()` on `A` with const or reference fields, before C++20

This is a followup on the answers for placement new on a class with reference field. Calling std::vector<A>::data() on type A that has reference or const

What is function designator and actual call?

According to C99 Standard: The order of evaluation of the function designator, the actual arguments, and subexpressions within the actual arguments is unspe

Inheriting a class and re-using its constructors issue missing in the base class

In the following program, struct B has two user-defined constructors: one from int and another from int&& (clearly this is not very practical). And an o

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