Namespaces
Variants
Actions

User:Fruderica

From natekohl.net

A Chinese C/C++ learner.

Contents

Experimental Templates

It is unspecified whether this identifier declared in <stdatomic.h> is a macro or an identifier declared with external linkage. If a macro definition is suppressed in order to access an actual function, or a program defines an external identifier with the name of a generic function, the behavior is undefined.

Special Symbols in C

Feature Test Macros

__STDC__
__STDC_ANALYZABLE__ (since C11)
__STDC_HOSTED__ (since C99)
__STDC_IEC_559__ (since C99)
__STDC_IEC_559_COMPLEX__ (since C99)
__STDC_ISO_10646__ (since C99)
__STDC_LIB_EXT1__ (since C11)
__STDC_MB_MIGHT_NEQ_WC__ (since C99)
__STDC_NO_ATOMICS__ (since C11)
__STDC_NO_COMPLEX__ (since C11)
__STDC_NO_THREADS__ (since C11)
__STDC_NO_VLA__ (since C11)
__STDC_UTF_16__ (since C11)
__STDC_UTF_32__ (since C11)
__STDC_VERSION__ (since C95)

__STDC_DEC_FP__ (decimal TR)
__STDC_ALLOC_LIB__ (dynamic memory TR)
__STDC_IEC_60559_BFP__ (FP Ext 1 TS)
__STDC_IEC_60559_COMPLEX__ (FP Ext 1 TS)
__STDC_IEC_60559_DFP__ (FP Ext2 TS)
__STDC_IEC_60559_TYPES__ (FP Ext3 TS)
__STDC_IEC_60559_FUNCS__ (FP Ext 4 TS)
__STDC_IEC_60559_ATTRIBS__ (FP Ext5 TS)
__STDC_IEC_60559_ATTRIB_ALTERNATE_EXCEPTION_HANDLING__ (FP Ext5 TS)

Other Predefined Macros

__DATE__
__FILE__
__LINE__
__TIME__

Special Identifiers

__VA_ARGS__ (since C99)

User Defined Macros

NDEBUG
__STDC_WANT_LIB_EXT1__ (since C11)

__STDC_WANT_DEC_FP__ (decimal TR)
__STDC_WANT_LIB_EXT2__ (dynamic memory TR)
__STDC_WANT_IEC_60559_BFP_EXT__ (FP Ext 1 TS)
__STDC_WANT_IEC_60559_DFP_EXT__ (FP Ext2 TS)
__STDC_WANT_IEC_60559_TYPES_EXT__ (FP Ext3 TS)
__STDC_WANT_IEC_60559_FUNCS_EXT__ (FP Ext 4 TS)
__STDC_WANT_IEC_60559_ATTRIBS_EXT__ (FP Ext5 TS)
__STDC_TGMATH_OPERATOR_EVALUATION__ (FP Ext5 TS)

Predefined Objects

__func__ (since C99)

Special User Defined Functions

main()

Macro Issue

  • Macros expanding to expressions of pointer types (such as stdin and FE_DFL_ENV) are not required to be address constant expression (even not required to be unmodifiable?).
  • Format string macros expand to string literals. However, string literals are not classified as constant expressions, even though they can be static objects themselves or initializers of static objects.
  • What's "variable" in C?
  1. "Variable" in The C Programming Language (K&R C) is identical to "object"
    ("string literal" may be a variable).
  2. "Variable" in C++ means "declared objects and declared references that are not non-static data members", which means "named objects and their subobjects" in C only as there are not reference types in C
    ("string literal" is not a variable; subset of K&R's definition).
  3. "Variable" in VLA means "nonconstant"
    (determined in run time; unmodifiable in run time; not required to be an lvalue).
  4. "Variable" in variable arguments means "number of function arguments may be different"
    (determined in compile time; unmodifiable in run time; even not an expression).
  5. Condition variables are not likely to be related to the issue...
  • errno meets K&R's definition.
  • MB_CUR_MAX is probably to meet "nonconstant" and not a lvalue.
  • It is unspecified that whether RSIZE_MAX expands to a lvalue expression!
  • Should this be used?
Macros Is modifiable lvalue? Is constant expression? Treated as constant?
stdin
stdout
stderr

FE_DFL_ENV
Unspecified Unspecified Yes
RSIZE_MAX Unspecified Unspecified Unknown
errno Yes No No
MB_CUR_MAX Probably no No No

Exposition-only items

Functions

decay-copy

template<class T>

constexpr std::decay_t<T> __decay_copy(T&& v)

    noexcept(std::is_nothrow_convertible_v<T, std::decay_t<T>>);

Returns std::forward<T>(v).

voidify

template<class T>
void* __voidify(T& obj) noexcept;

Returns const_cast<void*>(static_cast<const volatile void*>(std::addressof(obj))).

INVOKE

Equivalent to std::invoke(), except that it may be used in a constant expression?

FUN

void _FUN(T&) noexcept;
(1)
void _FUN(T&&) = delete;
(2)

Declaration only. They reject rvalue argument, and are used by some wrappers.

Reflection TS

The C++ Extensions for Reflection, ISO/IEC PDTS 23619:xxxx, specifies modifications to the core language and defines new components for the C++ standard library listed on this page.

Core language changes

Reflection TS introduces a new kind of type specifier called reflexpr-specifier and is of form reflexpr( reflexpr-operand ).

Syntax

There are several new syntax items introduced:

An alias is a name introduced by a typedef declaration, an alias-declaration, or a using-declaration.

reflexpr-operand can be one of following:

:: (1)
type-id (2)
nested-name-specifier(optional) namespace-name (3)
id-expression (4)
( expression ) (5)
function-call-expression (6)
functional-type-conv-expression (7)

where function-call-expression is

postfix-expression ( expression-list(optional) ) (1)

and functional-type-conv-expression are following sorts of expressions which perform explict cast:

simple-type-specifier ( expression-list(optional) ) (1)
typename-specifier ( expression-list(optional) ) (2)
simple-type-specifier braced-init-list (3)
typename-specifier braced-init-list (4)

For a reflexpr-operand of form ( expression ), the expression shall be a (possibly multi-parenthesized) function-call-expression or functional-type-conv-expression.

If a unparenthesized operand can be treated as either a type-id or a functional-type-conv-expression, then it is treated as a type-id. Parenthesizes can be used for disambiguation between function-style cast and a type-id. For example, given a class type X with default constructor, reflexpr(X()) reflects the function type X(), and reflexpr((X())) reflects the expression X().

Overload resolution

If the postfix-expression of the function-call-expression is of class type, i.e. e is of class type in the function-call-expression e(args), then the user-defined conversion function of the type of the postfix-expression (e) shall not be used. postfix-expression shall name a function that is the unique result of overload resolution if it is not of class type.

The program will be ill-formed if the expression fails to satisfy the requirements.

struct Functor {
    void operator()(int) const;
 
    using fptr_t = void(*)(std::nullptr_t);
    operator fptr_t() const;
};
 
using Meta0 = reflexpr(Functor{}(0));          // OK
// using Meta1 = reflexpr(Functor{}(nullptr)); // error: conversion function used

Meta-object types

The operand to the reflexpr-specifier shall be a type, namespace, enumerator, variable, structured binding, data member, function parameter, captured entity, function-call-expression or functionaltype-conv-expression, and parenthesized expression.

Types of reflexpr-specifier yields meta-object type which is an unnamed, incomplete namespace-scope class type. A type satisfies the requirement of concept reflect::Object if and only if it is a meta-object type. Meta-object types may satisfy other reflects, depending on the operand to reflexpr.

It is unspecified whether repeatedly applying reflexpr to the same operand yields the same type or a different type. If a meta-object type reflects an incomplete class type, certain type transformations cannot be applied.

A meta-object type allows inspection of some properties of the operand to reflexpr through type traits or type transformations on it.

Reflection-related

An entity or alias B is reflection-related to an entity or alias A if

  1. A and B are the same entity or alias,
  2. A is a variable or enumerator and B is the type of A,
  3. A is an enumeration and B is the underlying type of A,
  4. A is a class and B is a member or base class of A,
  5. A is a non-template alias that designates the entity B,
  6. A is not the global namespace and B is an enclosing class or namespace of A,
  7. A is the parenthesized expression ( B ),
  8. A is a lambda capture of the closure type B,
  9. A is the closure type of the lambda capture B,
  10. B is the type specified by the functional-type-conv-expression A,
  11. B is the function selected by overload resolution for a function-call-expression A,
  12. B is the return type, a parameter type, or function type of the function A, or
  13. B is reflection-related to an entity or alias X and X is reflection-related to A.

Reflection-relation relationship is reflexive and transitive, but not symmetric.

Informally speaking, the case that B is reflection-related to A means that B participates in the declaration or definition of A.

Zero or more successive applications of type transformations that yield meta-object types to the type denoted by a reflexpr-specifier enable inspection of entities and aliases that are reflection-related to the operand; such a meta-object type is said to reflect the respective reflection-related entity or alias.

struct X;
struct B {
    using X = ::X;
    typedef X Y;
};
struct D : B {
    using B::Y;
};
// ::X, but not B::X or B::Y is reflection-related to D::Y

Miscellaneous specification

  • An expression used as reflexpr-operand is an unevaluated expressions and potentially constant evaluated.
  • A function or variable of static storage duration reflected by meta-object type T is odr-used by the specialization std::experimental::reflect::get_pointer<T>, as if by taking the address of an id-expression nominating the function or variable.
  • There can be more than one definition of a meta-object type, as long as all operations on this type yield the same constant expression results.

Keywords

reflexpr

Concepts

Defined in header <experimental/reflect>
Defined in namespace std::experimental::reflect
Defined in inline namespace std::experimental::reflect::v1

Meta-object operations

Defined in header <experimental/reflect>
Defined in namespace std::experimental::reflect
Defined in inline namespace std::experimental::reflect::v1

Compiler support issues

A lot of patch/DR/DR-like papers.

C++11 core

  • N2634 Expression SFINAE; for some old compilers

C++11 library

Almost all C++11 library features are missing.

  • C99 standard library
  • Type traits
  • Unordered containers
  • array
  • tuple
  • shared_ptr and weak_ptr
  • Regular expression library
  • function, referenc_wrapper, etc.
  • Random number generation N2111
  • emplace/emplace_back N2345
  • etc.
  • forward_list N2543
  • Date and time library N2661(?)
  • etc.

C++20 core

  • P1236R1 Signed integers are two's complement (eliminate some undefined behavior); for MSVC