Date:  2023-11-11
Project:  Programming Language C++
Reference:  ISO/IEC IS 14882:2020
Reply to:  Jens Maurer
 jens.maurer@gmx.net


C++ Standard Core Language Active Issues, Revision 112d


This document contains the C++ core language issues on which the Committee (INCITS PL22.16 + WG21) has not yet acted, that is, issues with status "Ready," "Tentatively Ready," "Review," "Drafting," and "Open." (See Issue Status below.)

This document is part of a group of related documents that together describe the issues that have been raised regarding the C++ Standard. The other documents in the group are:

Section references in this document reflect the section numbering of document WG21 N4958.

The purpose of these documents is to record the disposition of issues that have come before the Core Language Working Group of the ANSI (INCITS PL22.16) and ISO (WG21) C++ Standard Committee.

Some issues represent potential defects in the ISO/IEC IS 14882:2020 document and corrected defects in the earlier 2017, 2014, 2011, 2003, and 1998 documents; others refer to text in the working draft for the next revision of the C++ language and not to any Standard text. Issues are not necessarily formal ISO Defect Reports (DRs). While some issues will eventually be elevated to DR status, others will be disposed of in other ways.

The most current public version of this document can be found at http://www.open-std.org/jtc1/sc22/wg21. Requests for further information about these documents should include the document number, reference ISO/IEC 14882:2020, and be submitted to the InterNational Committee for Information Technology Standards (INCITS), 1250 Eye Street NW, Suite 200, Washington, DC 20005, USA.

Information regarding C++ standardization can be found at http://isocpp.org/std.


Revision History

Issue status

Issues progress through various statuses as the Core Language Working Group and, ultimately, the full PL22.16 and WG21 committees deliberate and act. For ease of reference, issues are grouped in these documents by their status. Issues have one of the following statuses:

Open: The issue is new or the working group has not yet formed an opinion on the issue. If a Suggested Resolution is given, it reflects the opinion of the issue's submitter, not necessarily that of the working group or the Committee as a whole.

Drafting: Informal consensus has been reached in the working group and is described in rough terms in a Tentative Resolution, although precise wording for the change is not yet available.

Review: Exact wording of a Proposed Resolution is now available for an issue on which the working group previously reached informal consensus.

Ready: The working group has reached consensus that a change in the working draft is required, the Proposed Resolution is correct, and the issue is ready to forward to the full Committee for ratification.

Tentatively Ready: Like "ready" except that the resolution was produced and approved by a subset of the working group membership between meetings. Persons not participating in these between-meeting activities are encouraged to review such resolutions carefully and to alert the working group with any problems that may be found.

DR: The full Committee has approved the item as a proposed defect report. The Proposed Resolution in an issue with this status reflects the best judgment of the Committee at this time regarding the action that will be taken to remedy the defect; however, the current wording of the Standard remains in effect until such time as a Technical Corrigendum or a revision of the Standard is issued by ISO.

accepted: Like a DR except that the issue concerns the wording of the current Working Paper rather than that of the current International Standard.

TC1: A DR issue included in Technical Corrigendum 1. TC1 is a revision of the Standard issued in 2003.

CD1: A DR issue not resolved in TC1 but included in Committee Draft 1. CD1 was advanced for balloting at the September, 2008 WG21 meeting.

CD2: A DR issue not resolved in CD1 but included in the Final Committee Draft advanced for balloting at the March, 2010 WG21 meeting.

C++11: A DR issue not resolved in CD2 but included in ISO/IEC 14882:2011.

CD3: A DR/DRWP or Accepted/WP issue not resolved in C++11 but included in the Committee Draft advanceed for balloting at the April, 2013 WG21 meeting.

C++14: A DR/DRWP or Accepted/WP issue not resolved in CD3 but included in ISO/IEC 14882:2014.

CD4: A DR/DRWP or Accepted/WP issue not resolved in C++14 but included in the Committee Draft advanced for balloting at the June, 2016 WG21 meeting.

C++17: a DR/DRWP or Accepted/WP issue not resolved in CD4 but included in ISO/IEC 14882:2017.

CD5: A DR/DRWP or Accepted/WP issue not resolved in C++17 but included in the Committee Draft advanced for balloting at the July, 2019 WG21 meeting.

C++20: a DR/DRWP or Accepted/WP issue not resolved in CD5 but included in ISO/IEC 14882:2020.

CD6: A DR/DRWP or Accepted/WP issue not resolved in C++20 but included in the Committee Draft advanced for balloting at the July, 2022 WG21 meeting.

C++23: a DR/DRWP or Accepted/WP issue not resolved in CD6 but included in ISO/IEC 14882:2023.

DRWP: A DR issue whose resolution is reflected in the current Working Paper. The Working Paper is a draft for a future version of the Standard.

WP: An accepted issue whose resolution is reflected in the current Working Paper.

Dup: The issue is identical to or a subset of another issue, identified in a Rationale statement.

NAD: The working group has reached consensus that the issue is not a defect in the Standard. A Rationale statement describes the working group's reasoning.

Extension: The working group has reached consensus that the issue is not a defect in the Standard but is a request for an extension to the language. The working group expresses no opinion on the merits of an issue with this status; however, the issue will be maintained on the list for possible future consideration as an extension proposal.

Concepts: The issue relates to the “Concepts” proposal that was removed from the working paper at the Frankfurt (July, 2009) meeting and hence is no longer under consideration.


Overview

Section Issue Status Liaison Title
intro.defs 783 open Definition of “argument”
intro.defs 2632 review 'user-declared' is not defined
4.1  intro.compliance 949 open Requirements for freestanding implementations
4.1.1  intro.compliance.general 2700 review WG14 #error disallows existing implementation practice
4.1.1  intro.compliance.general 2776 open EWG Substitution failure and implementation limits
5.2  lex.phases 1698 ready Files ending in \
5.2  lex.phases 2747 ready Cannot depend on an already-deleted splice
5.3  lex.charset 2779 open Restrictions on the ordinary literal encoding
5.4  lex.pptoken 369 drafting Are new/delete identifiers or preprocessing-op-or-punc?
5.4  lex.pptoken 1655 drafting Line endings in raw string literals
5.5  lex.digraph 2726 review EWG Alternative tokens appearing as attribute-tokens
5.6  lex.token 1901 drafting punctuator referenced but not defined
5.10  lex.name 2818 open Use of predefined reserved identifiers
5.12  lex.operators 189 drafting Definition of operator and punctuator
5.13  lex.literal 1924 review editor Definition of “literal” and kinds of literals
5.13.4  lex.fcon 2752 open EWG Excess-precision floating-point literals
5.13.5  lex.string 2766 open Repeated evaluation of a string-literal may yield different objects
5.13.9  lex.ext 1266 open user-defined-integer-literal overflow
5.13.9  lex.ext 1723 drafting Multicharacter user-defined character literals
5.13.9  lex.ext 1735 drafting Out-of-range literals in user-defined-literals
6.1  basic.pre 1529 drafting Nomenclature for variable vs reference non-static data member
6.3  basic.def.odr 1209 open Is a potentially-evaluated expression in a template definition a “use?”
6.3  basic.def.odr 1897 review ODR vs alternative tokens
6.3  basic.def.odr 2745 open Dependent odr-use in generic lambdas
6.3  basic.def.odr 2781 open Unclear recursion in the one-definition rule
6.3  basic.def.odr 2782 open Treatment of closure types in the one-definition rule
6.4.1  basic.scope.scope 2488 open Overloading virtual functions and functions with trailing requires-clauses
6.4.1  basic.scope.scope 2764 ready Use of placeholders affecting name mangling
6.4.1  basic.scope.scope 2788 open Correspondence and redeclarations
6.4.3  basic.scope.block 2793 ready Block-scope declaration conflicting with parameter name
6.5.1  basic.lookup.general 2480 drafting Lookup for enumerators in modules
6.5.2  class.member.lookup 380 open Definition of "ambiguous base class" missing
6.5.5.1  basic.lookup.qual.general 1089 drafting Template parameters in member selections
6.6  basic.link 2670 open Programs and translation units
6.6  basic.link 2706 open Repeated structured binding declarations
6.7.1  intro.memory 1953 open Data races and common initial sequence
6.7.2  intro.object 2324 drafting Size of base class subobject
6.7.2  intro.object 2325 drafting std::launder and reuse of character buffers
6.7.2  intro.object 2334 open Creation of objects by typeid
6.7.2  intro.object 2469 drafting Implicit object creation vs constant expressions
6.7.2  intro.object 2744 open Multiple objects of the same type at the same address
6.7.2  intro.object 2753 ready Storage reuse for string literal objects and backing arrays
6.7.2  intro.object 2765 open Address comparisons between potentially non-unique objects during constant evaluation
6.7.2  intro.object 2795 ready Overlapping empty subobjects with different cv-qualification
6.7.3  basic.life 419 open Can cast to virtual base class be done on partially-constructed object?
6.7.3  basic.life 1027 drafting Type consistency and reallocation of scalar types
6.7.3  basic.life 1530 drafting Member access in out-of-lifetime objects
6.7.3  basic.life 2258 open Storage deallocation during period of destruction
6.7.3  basic.life 2514 open SG12 Modifying const subobjects
6.7.3  basic.life 2551 review "Refers to allocated storage" has no meaning
6.7.3  basic.life 2676 open Replacing a complete object having base subobjects
6.7.3  basic.life 2677 review Replacing union subobjects
6.7.3  basic.life 2821 open Lifetime, zero-initialization, and dynamic initialization
6.7.4  basic.indet 1997 drafting Placement new and previous initialization
6.7.5  basic.stc 365 open Storage duration and temporaries
6.7.5  basic.stc 1634 drafting Temporary storage duration
6.7.5  basic.stc 2533 review Storage duration of implicitly created objects
6.7.5.1  basic.stc.general 2822 tentatively ready Side-effect-free pointer zap
6.7.5.5.2  basic.stc.dynamic.allocation 1676 drafting auto return type for allocation and deallocation functions
6.7.5.5.2  basic.stc.dynamic.allocation 1682 open Overly-restrictive rules on function templates as allocation functions
6.7.5.5.2  basic.stc.dynamic.allocation 2073 drafting Allocating memory for exception objects
6.7.5.5.3  basic.stc.dynamic.deallocation 523 open Can a one-past-the-end pointer be invalidated by deleting an adjacent object?
6.7.5.5.3  basic.stc.dynamic.deallocation 2042 drafting Exceptions and deallocation functions
6.7.6  basic.align 1211 drafting Misaligned lvalues
6.7.7  class.temporary 2434 open Mandatory copy elision vs non-class objects
6.7.7  class.temporary 2666 open Lifetime extension through static_cast
6.7.7  class.temporary 2826 tentatively ready Missing definition of "temporary expression"
6.7.7  class.temporary 2832 open Invented temporary variables and temporary objects
6.8  basic.types 350 open WG14 signed char underlying representation for objects
6.8  basic.types 1701 drafting Array vs sequence in object representation
6.8.2  basic.fundamental 146 open Floating-point zero
6.8.2  basic.fundamental 251 open How many signed integer types are there?
6.8.2  basic.fundamental 2689 review Are cv-qualified std::nullptr_t fundamental types?
6.8.2  basic.fundamental 2827 review Representation of unsigned integral types
6.8.4  basic.compound 2544 open Address of past-the-end of a potentially-overlapping subobject
6.9.1  intro.execution 698 open The definition of “sequenced before” is too narrow
6.9.2  intro.multithread 1842 open SG1 Unevaluated operands and “carries a dependency”
6.9.2.2  intro.races 2297 open Unclear specification of atomic operations
6.9.2.2  intro.races 2298 open SG1 Actions and expression evaluation
6.9.2.2  intro.races 2587 review Visible side effects and initial value of an object
6.9.2.3  intro.progress 2816 open Unclear phrasing "may assume ... eventually"
6.9.3.1  basic.start.main 2811 open Clarify "use" of main
6.9.3.2  basic.start.static 371 open Interleaving of constructor calls
6.9.3.2  basic.start.static 1294 open Side effects in dynamic/static initialization
6.9.3.2  basic.start.static 1659 open Initialization order of thread_local template static data members
6.9.3.2  basic.start.static 1986 drafting odr-use and delayed initialization
6.9.3.2  basic.start.static 2148 drafting Thread storage duration and order of initialization
6.9.3.3  basic.start.dynamic 2444 drafting Constant expressions in initialization odr-use
6.9.3.3  basic.start.dynamic 2684 open thread_local dynamic initialization
7.3.6  conv.qual 2438 open Problems in the specification of qualification conversions
7.5.4  expr.prim.id 2503 drafting Unclear relationship among name, qualified name, and unqualified name
7.5.4.2  expr.prim.id.unqual 2738 review "denotes a destructor" is missing specification
7.5.4.3  expr.prim.id.qual 2549 review Implicitly moving the operand of a throw-expression in unevaluated contexts
7.5.4.4  expr.prim.id.dtor 2473 drafting Parentheses in pseudo-destructor calls
7.5.5.2  expr.prim.lambda.closure 2561 review EWG Conversion to function pointer for lambda with explicit object parameter
7.5.5.3  expr.prim.lambda.capture 2086 drafting Reference odr-use vs implicit capture
7.5.5.3  expr.prim.lambda.capture 2737 open Temporary lifetime extension for reference init-captures
7.5.7.1  expr.prim.req.general 2560 tentatively ready EWG Parameter type determination in a requirement-parameter-list
7.5.7.1  expr.prim.req.general 2565 open EWG Invalid types in the parameter-declaration-clause of a requires-expression
7.5.7.5  expr.prim.req.nested 2739 open Nested requirement not a constant expression
7.6.1.3  expr.call 2284 open Sequencing of braced-init-list arguments
7.6.1.3  expr.call 2515 open Result of a function call
7.6.1.3  expr.call 2660 open Confusing term "this parameter"
7.6.1.3  expr.call 2688 open Calling explicit object member functions
7.6.1.4  expr.type.conv 914 open EWG Value-initialization of array types
7.6.1.4  expr.type.conv 1521 drafting T{expr} with reference types
7.6.1.4  expr.type.conv 2283 drafting Missing complete type requirements
7.6.1.5  expr.ref 2557 drafting Class member access referring to an unrelated class
7.6.1.5  expr.ref 2705 open Accessing ambiguous subobjects
7.6.1.5  expr.ref 2725 ready Overload resolution for non-call of class member access
7.6.1.5  expr.ref 2748 open Accessing static data members via null pointer
7.6.1.5  expr.ref 2813 open Class member access with prvalues
7.6.1.6  expr.post.incr 742 open Postfix increment/decrement with long bit-field operands
7.6.1.7  expr.dynamic.cast 1965 drafting Explicit casts to reference types
7.6.1.8  expr.typeid 282 open Namespace for extended_type_info
7.6.1.8  expr.typeid 1954 tentatively ready typeid null dereference check in subexpressions
7.6.1.9  expr.static.cast 2048 open C-style casts that cast away constness vs static_cast
7.6.1.9  expr.static.cast 2243 drafting Incorrect use of implicit conversion sequence
7.6.1.9  expr.static.cast 2814 open Alignment requirement of undefined class type
7.6.1.10  expr.reinterpret.cast 2780 ready reinterpret_cast to reference to function types
7.6.2.2  expr.unary.op 2823 ready Implicit undefined behavior when dereferencing pointers
7.6.2.4  expr.await 2668 tentatively ready co_await in a lambda-expression
7.6.2.5  expr.sizeof 2609 open Padding in class types
7.6.2.5  expr.sizeof 2817 open sizeof(abstract class) is underspecified
7.6.2.7  expr.unary.noexcept 2792 ready Clean up specification of noexcept operator
7.6.2.8  expr.new 267 open Alignment requirement for new-expressions
7.6.2.8  expr.new 901 drafting Deleted operator delete
7.6.2.8  expr.new 1628 open Deallocation function templates
7.6.2.8  expr.new 2102 ready Constructor checking in new-expression
7.6.2.8  expr.new 2281 drafting Consistency of aligned operator delete replacement
7.6.2.8  expr.new 2532 open Kind of pointer value returned by new T[0]
7.6.2.8  expr.new 2566 review Matching deallocation for uncaught exception
7.6.2.8  expr.new 2592 open Missing definition for placement allocation/deallocation function
7.6.2.8  expr.new 2623 drafting Invoking destroying operator delete for constructor failure
7.6.2.8  expr.new 2812 open Allocation with explicit alignment
7.6.2.9  expr.delete 196 open Arguments to deallocation functions
7.6.2.9  expr.delete 2728 open Evaluation of conversions in a delete-expression
7.6.2.9  expr.delete 2758 ready What is "access and ambiguity control"?
7.6.2.9  expr.delete 2805 open Underspecified selection of deallocation function
7.6.3  expr.cast 2828 review Ambiguous interpretation of C-style cast
7.6.4  expr.mptr.oper 2593 review Insufficient base class restriction for pointer-to-member expression
7.6.6  expr.add 2013 drafting Pointer subtraction in large array
7.6.6  expr.add 2182 drafting Pointer arithmetic in array-like containers
7.6.9  expr.rel 2749 ready SG22 Treatment of "pointer to void" for relational comparisons
7.6.9  expr.rel 2796 ready Function pointer conversions for relational operators
7.6.10  expr.eq 2786 open Comparing pointers to complete objects
7.6.16  expr.cond 2023 drafting Composite reference result type of conditional operator
7.6.16  expr.cond 2316 drafting Simplifying class conversions in conditional expressions
7.6.19  expr.ass 1542 drafting Compound assignment of braced-init-list
7.6.19  expr.ass 2768 ready Assignment to enumeration variable with a braced-init-list
7.7  expr.const 1255 drafting Definition problems with constexpr functions
7.7  expr.const 1256 open Unevaluated operands are not necessarily constant expressions
7.7  expr.const 1626 open constexpr member functions in brace-or-equal-initializers
7.7  expr.const 2166 drafting Unclear meaning of “undefined constexpr function”
7.7  expr.const 2186 drafting Unclear point that “preceding initialization” must precede
7.7  expr.const 2192 open Constant expressions and order-of-eval undefined behavior
7.7  expr.const 2301 open Value-initialization and constexpr constructor evaluation
7.7  expr.const 2456 open Viable user-defined conversions in converted constant expressions
7.7  expr.const 2536 open EWG Partially initialized variables during constant initialization
7.7  expr.const 2545 open Transparently replacing objects in constant expressions
7.7  expr.const 2559 open Defaulted consteval functions
7.7  expr.const 2633 open typeid of constexpr-unknown dynamic type
7.7  expr.const 2656 drafting Converting consteval lambda to function pointer in non-immediate context
7.7  expr.const 2702 open Constant destruction of reference members
7.7  expr.const 2734 open Immediate forward-declared function templates
7.7  expr.const 2740 open Too many objects have constexpr-unknown type
7.7  expr.const 2755 ready Incorrect wording applied by P2738R1
7.7  expr.const 2760 ready Defaulted constructor that is an immediate function
7.7  expr.const 2763 ready Ignorability of [[noreturn]] during constant evaluation
7.7  expr.const 2778 open Trivial destructor does not imply constant destruction
7.7  expr.const 2798 ready Manifestly constant evaluation of the static_assert message
7.7  expr.const 2800 review Instantiating constexpr variables for potential constant evaluation
7.7  expr.const 2819 open Cast from null pointer value in a constant expression
8.6.5  stmt.ranged 1680 drafting Including <initializer_list> for range-based for
8.6.5  stmt.ranged 2825 tentatively ready EWG Range-based for statement using a braced-init-list
8.7  stmt.jump 2115 drafting Order of implicit destruction vs release of automatic storage
8.7.4  stmt.return 2495 open Glvalue result of a function call
8.7.4  stmt.return 2791 ready Unclear phrasing about "returning to the caller"
8.7.5  stmt.return.coroutine 2556 ready Unusable promise::return_void
8.8  stmt.dcl 2123 open Omitted constant initialization of local static variables
8.9  stmt.ambig 1223 drafting Syntactic disambiguation and trailing-return-types
9.1  dcl.pre 157 open Omitted typedef declarator
9.2.2  dcl.stc 498 open Storage class specifiers in definitions of class members
9.2.2  dcl.stc 2232 open thread_local anonymous unions
9.2.6  dcl.constexpr 2117 drafting Explicit specializations and constexpr function templates
9.2.6  dcl.constexpr 2531 ready Static data members redeclared as constexpr
9.2.9.2  dcl.type.cv 2195 open Unsolicited reading of trailing volatile members
9.2.9.4  dcl.type.elab 144 open Position of friend specifier
9.2.9.4  dcl.type.elab 2634 tentatively ready Avoid circularity in specification of scope for friend class declarations
9.2.9.6  dcl.spec.auto 1348 drafting Use of auto in a trailing-return-type
9.2.9.6  dcl.spec.auto 1670 drafting auto as conversion-type-id
9.2.9.6  dcl.spec.auto 1868 drafting Meaning of “placeholder type”
9.2.9.6  dcl.spec.auto 2412 review SFINAE vs undeduced placeholder type
9.2.9.6.1  dcl.spec.auto.general 2476 tentatively ready placeholder-type-specifiers and function declarators
9.3.1  dcl.decl.general 2831 open Non-templated function definitions and requires-clauses
9.3.2  dcl.name 1488 drafting abstract-pack-declarators in type-ids
9.3.3  dcl.ambig.res 2228 open EWG Ambiguity resolution for cast to function type
9.3.4.1  dcl.meaning.general 2671 open friend named by a template-id
9.3.4.3  dcl.ref 453 review References may only bind to “valid” objects
9.3.4.6  dcl.fct 1001 drafting Parameter type adjustment in dependent parameter types
9.3.4.6  dcl.fct 1668 drafting Parameter type determination still not clear enough
9.3.4.6  dcl.fct 1790 open EWG Ellipsis following function parameter pack
9.3.4.6  dcl.fct 2537 drafting Overbroad grammar for parameter-declaration
9.3.4.6  dcl.fct 2553 review Restrictions on explicit object member functions
9.3.4.6  dcl.fct 2802 open Constrained auto and redeclaration with non-abbreviated syntax
9.3.4.7  dcl.fct.default 325 drafting When are default arguments parsed?
9.3.4.7  dcl.fct.default 361 open Forward reference to default argument
9.3.4.7  dcl.fct.default 1580 drafting Default arguments in explicit instantiations
9.3.4.7  dcl.fct.default 1609 open Default arguments and function parameter packs
9.3.4.7  dcl.fct.default 2701 open Default arguments in multiple scopes / inheritance of array bounds in the same scope
9.4  dcl.init 2327 drafting Copy elision for direct-initialization with a conversion function
9.4.1  dcl.init.general 2820 open Value-initialization and default constructors
9.4.1  dcl.init.general 2824 tentatively ready Copy-initialization of arrays
9.4.2  dcl.init.aggr 2128 drafting Imprecise rule for reference member initializer
9.4.2  dcl.init.aggr 2149 drafting Brace elision and array length deduction
9.4.3  dcl.init.string 1304 drafting Omitted array bound with string initialization
9.4.4  dcl.init.ref 233 drafting References vs pointers in UDC overload resolution
9.4.4  dcl.init.ref 1414 drafting Binding an rvalue reference to a reference-unrelated lvalue
9.4.4  dcl.init.ref 1827 drafting Reference binding with ambiguous conversions
9.4.4  dcl.init.ref 2657 tentatively ready Cv-qualification adjustment when binding reference to temporary
9.4.4  dcl.init.ref 2704 open Clarify meaning of "bind directly"
9.4.4  dcl.init.ref 2801 ready Reference binding with reference-related types
9.4.5  dcl.init.list 1996 drafting Reference list-initialization ignores conversion functions
9.4.5  dcl.init.list 2168 open Narrowing conversions and +/- infinity
9.4.5  dcl.init.list 2252 ready Enumeration list-initialization from the same type
9.4.5  dcl.init.list 2638 tentatively ready Improve the example for initializing by initializer list
9.4.5  dcl.init.list 2742 open Guaranteed copy elision for brace-initialization from prvalue
9.4.5  dcl.init.list 2830 open Top-level cv-qualification should be ignored for list-initialization
9.5.1  dcl.fct.def.general 1962 open EWG Type of __func__
9.5.1  dcl.fct.def.general 2144 drafting Function/variable declaration ambiguity
9.5.1  dcl.fct.def.general 2362 open EWG __func__ should be constexpr
9.5.2  dcl.fct.def.default 1854 drafting Disallowing use of implicitly-deleted functions
9.5.2  dcl.fct.def.default 2547 review Defaulted comparison operator function for non-classes
9.5.2  dcl.fct.def.default 2570 ready Clarify constexpr for defaulted functions
9.5.2  dcl.fct.def.default 2809 open An implicit definition does not redeclare a function
9.5.4  dcl.fct.def.coroutine 2562 open Exceptions thrown during coroutine startup
9.5.4  dcl.fct.def.coroutine 2563 drafting EWG Initialization of coroutine result object
9.5.4  dcl.fct.def.coroutine 2754 ready Using *this in explicit object member functions that are coroutines
9.6  dcl.struct.bind 2340 open Reference collapsing and structured bindings
9.7.1  dcl.enum 1485 drafting Out-of-class definition of member unscoped opaque enumeration
9.7.1  dcl.enum 2131 drafting Ambiguity with opaque-enum-declaration
9.8.2.2  namespace.unnamed 2505 drafting Nested unnamed namespace of inline unnamed namespace
9.9  namespace.udecl 813 open typename in a using-declaration with a non-dependent name
9.9  namespace.udecl 2555 drafting Ineffective redeclaration prevention for using-declarators
9.11  dcl.link 1817 drafting Linkage specifications and nested scopes
9.12.1  dcl.attr.grammar 1706 drafting alignas pack expansion syntax
9.12.2  dcl.align 1617 open alignas and non-defining declarations
9.12.2  dcl.align 2223 drafting Multiple alignas specifiers
9.12.8  dcl.attr.unused 2733 ready EWG Applying [[maybe_unused]] to a label
10.1  module.unit 2541 open Linkage specifications, module purview, and module attachment
10.2  module.interface 2607 drafting Visibility of enumerator names
10.3  module.import 2727 open Importing header units synthesized from source files
10.4  module.global.frag 2783 ready Handling of deduction guides in global-module-fragment
11.1  class.pre 2637 tentatively ready Injected-class-name as a simple-template-id
11.2  class.prop 511 open POD-structs with template assignment operators
11.2  class.prop 2463 open EWG Trivial copyability and unions with non-trivial members
11.2  class.prop 2736 open Standard layout class with empty base class also in first member
11.4  class.mem 1890 drafting Member type depending on definition of member function
11.4.1  class.mem.general 2188 open empty-declaration grammar ambiguity
11.4.1  class.mem.general 2661 open Missing disambiguation rule for pure-specifier vs. brace-or-equal-initializer
11.4.1  class.mem.general 2759 ready [[no_unique_address] and common initial sequence
11.4.3  class.mfct.non.static 2771 open Transformation for unqualified-ids in address operator
11.4.4  special 2595 ready "More constrained" for eligible special member functions
11.4.4  special 2787 open Kind of explicit object copy/move assignment function
11.4.5  class.ctor 1623 drafting Deleted default union constructor and member initializers
11.4.5  class.ctor 1808 drafting Constructor templates vs default constructors
11.4.5.2  class.default.ctor 2799 drafting Inheriting default constructors
11.4.5.3  class.copy.ctor 1092 drafting Cycles in overload resolution during instantiation
11.4.5.3  class.copy.ctor 1548 drafting Copy/move construction and conversion functions
11.4.5.3  class.copy.ctor 1594 drafting Lazy declaration of special members vs overload errors
11.4.5.3  class.copy.ctor 2203 drafting Defaulted copy/move constructors and UDCs
11.4.5.3  class.copy.ctor 2264 drafting Memberwise copying with indeterminate value
11.4.5.3  class.copy.ctor 2743 open Copying non-trivial objects nested within a union
11.4.6  class.copy.assign 1499 drafting Missing case for deleted move assignment operator
11.4.6  class.copy.assign 2329 drafting Virtual base classes and generated assignment operators
11.4.7  class.dtor 1977 drafting Contradictory results of failed destructor lookup
11.4.7  class.dtor 2158 drafting Polymorphic behavior during destruction
11.4.7  class.dtor 2761 ready Implicitly invoking the deleted destructor of an anonymous union member
11.4.7  class.dtor 2807 ready Destructors declared consteval
11.4.8.3  class.conv.fct 2513 open Ambiguity with requires-clause and operator-function-id
11.4.9.3  class.static.data 1283 drafting Static data members of classes with typedef name for linkage purposes
11.4.9.3  class.static.data 1721 drafting Diagnosing ODR violations for static data members
11.4.9.3  class.static.data 2335 drafting Deduced return types vs member types
11.5  class.union 57 open Empty unions
11.5  class.union 1404 drafting Object reallocation in unions
11.5  class.union 1702 drafting Rephrasing the definition of “anonymous union”
11.5.1  class.union.general 2591 ready Implicit change of active union member for anonymous union in union
11.5.1  class.union.general 2675 open start_lifetime_as, placement-new, and active union members
11.5.2  class.union.anon 2767 open Non-defining declarations of anonymous unions
11.5.2  class.union.anon 2773 open Naming anonymous union members as class members
11.7.3  class.virtual 2554 review Overriding virtual functions, also with explicit object parameters
11.8.3  class.access.base 2246 drafting Access of indirect virtual base class constructors
11.8.4  class.friend 1699 open EWG Does befriending a class befriend its friends?
11.8.4  class.friend 2588 drafting EWG friend declarations and module linkage
11.8.5  class.protected 472 drafting Casting across protected inheritance
11.8.5  class.protected 1883 drafting Protected access to constructors in mem-initializers
11.8.5  class.protected 2187 drafting Protected members and access via qualified-id
11.8.5  class.protected 2244 open Base class access in aggregate initialization
11.9  class.init 2756 review Completion of initialization by delegating constructor
11.9.3  class.base.init 1915 open EWG Potentially-invoked destructors in non-throwing constructors
11.9.3  class.base.init 2056 drafting Member function calls in partially-initialized class objects
11.9.3  class.base.init 2403 drafting Temporary materialization and base/member initialization
11.9.3  class.base.init 2669 open EWG Lifetime extension for aggregate initialization
11.9.4  class.inhctor.init 2504 ready Inheriting constructors from virtual base classes
11.9.5  class.cdtor 1517 drafting Unclear/missing description of behavior during construction/destruction
11.9.5  class.cdtor 2757 review Deleting or deallocating storage of an object during its construction
11.9.6  class.copy.elision 1049 open Copy elision through reference parameters of inline functions
11.10.1  class.compare.default 2568 review Access checking during synthesis of defaulted comparison operator
11.10.3  class.spaceship 2703 review Three-way comparison requiring strong ordering for floating-point types, take 2
11.10.4  class.compare.secondary 2546 tentatively ready Defaulted secondary comparison operators defined as deleted
12.2.2.1  over.match.funcs.general 2762 ready Type of implicit object parameter
12.2.2.2.2  over.call.func 1278 drafting Incorrect treatment of contrived object
12.2.2.2.3  over.call.object 2189 open Surrogate call template
12.2.2.2.3  over.call.object 2564 drafting Conversion to function pointer with an explicit object parameter
12.2.2.3  over.match.oper 545 open User-defined conversions and built-in operator overload resolution
12.2.2.3  over.match.oper 1919 open Overload resolution for ! with explicit conversion operator
12.2.2.3  over.match.oper 2089 drafting Restricting selection of builtin overloaded operators
12.2.2.3  over.match.oper 2730 open Comparison templates on enumeration types
12.2.2.3  over.match.oper 2797 open EWG Meaning of "corresponds" for rewritten operator candidates
12.2.2.3  over.match.oper 2804 open EWG Lookup for determining rewrite targets
12.2.2.7  over.match.ref 2028 drafting Converting constructors in rvalue reference initialization
12.2.2.7  over.match.ref 2108 drafting Conversions to non-class prvalues in reference initialization
12.2.2.8  over.match.list 2194 drafting Impossible case in list initialization
12.2.2.8  over.match.list 2311 open Missed case for guaranteed copy elision
12.2.2.9  over.match.class.deduct 2425 open Confusing wording for deduction from a type
12.2.2.9  over.match.class.deduct 2467 drafting CTAD for alias templates and the deducible check
12.2.2.9  over.match.class.deduct 2471 drafting Nested class template argument deduction
12.2.2.9  over.match.class.deduct 2628 ready Implicit deduction guides should propagate constraints
12.2.2.9  over.match.class.deduct 2680 open Class template argument deduction for aggregates with designated initializers
12.2.2.9  over.match.class.deduct 2714 open Implicit deduction guides omit properties from the parameter-declaration-clause of a constructor
12.2.4  over.match.best 2735 open List-initialization and conversions in overload resolution
12.2.4.1  over.match.best.general 2789 ready Overload resolution with implicit and explicit object member functions
12.2.4.2  over.best.ics 2319 drafting Nested brace initialization from same type
12.2.4.2.1  over.best.ics.general 2525 drafting Incorrect definition of implicit conversion sequence
12.2.4.2.1  over.best.ics.general 2679 open Implicit conversion sequence with a null pointer constant
12.2.4.2.1  over.best.ics.general 2829 open Redundant case in restricting user-defined conversion sequences
12.2.4.2.3  over.ics.user 2731 open List-initialization sequence with a user-defined conversion
12.2.4.2.5  over.ics.ref 2077 drafting Overload resolution and invalid rvalue-reference initialization
12.2.4.2.5  over.ics.ref 2803 tentatively ready Overload resolution for reference binding of similar types
12.2.4.2.6  over.ics.list 1536 drafting Overload resolution with temporary from initializer list
12.2.4.2.6  over.ics.list 2169 open Narrowing conversions and overload resolution
12.2.4.2.6  over.ics.list 2492 drafting Comparing user-defined conversion sequences in list-initialization
12.2.4.2.6  over.ics.list 2741 open Implicit conversion sequence from empty list to array of unknown bound
12.2.4.2.6  over.ics.list 2790 open Aggregate initialization and user-defined conversion sequence
12.2.4.3  over.ics.rank 1459 open Reference-binding tiebreakers in overload resolution
12.2.4.3  over.ics.rank 1789 open Array reference vs array decay in overload resolution
12.2.4.3  over.ics.rank 2110 drafting Overload resolution for base class conversion and reference/non-reference
12.2.4.3  over.ics.rank 2337 open Incorrect implication of logic ladder for conversion sequence tiebreakers
12.2.4.3  over.ics.rank 2815 open Overload resolution for references/pointers to noexcept functions
12.3  over.over 1038 ready Overload resolution of &x.static_func
12.3  over.over 2572 review Address of overloaded function with no target
12.4  over.oper 1989 drafting Insufficient restrictions on parameters of postfix operators
12.4.3  over.binary 1549 open Overloaded comma operator with void operand
12.5  over.built 260 open User-defined conversions and built-in operator=
12.5  over.built 954 open Overload resolution of conversion operator templates with built-in types
12.6  over.literal 1620 open User-defined literals and extended integer types
13  temp 205 drafting Templates and static data members
13.1  temp.pre 1463 drafting EWG extern "C" alias templates
13.2  temp.param 1444 drafting Type adjustments of non-type template parameters
13.2  temp.param 1635 drafting How similar are template default arguments to function default arguments?
13.2  temp.param 2395 drafting Parameters following a pack expansion
13.2  temp.param 2617 review Default template arguments for template members of non-template classes
13.2  temp.param 2777 open Type of id-expression denoting a template parameter object
13.3  temp.names 579 open What is a “nested” > or >>?
13.3  temp.names 2450 review braced-init-list as a template-argument
13.4  temp.arg 2105 open When do the arguments for a parameter pack end?
13.4.3  temp.arg.nontype 2043 drafting Generalized template arguments and array-to-pointer decay
13.4.3  temp.arg.nontype 2049 drafting List initializer in non-type template default argument
13.4.3  temp.arg.nontype 2401 drafting Array decay vs prohibition of subobject non-type arguments
13.4.3  temp.arg.nontype 2459 drafting Template parameter initialization
13.4.4  temp.arg.template 2057 drafting Template template arguments with default arguments
13.4.4  temp.arg.template 2398 drafting Template template parameter matching and deduction
13.5.2  temp.constr.constr 2686 open Pack expansion into a non-pack parameter of a concept
13.5.2.3  temp.constr.atomic 2589 review Context of access checks during constraint satisfaction checking
13.6  temp.type 2037 drafting Alias templates and template declaration matching
13.7  temp.decls 1730 drafting Can a variable template have an unnamed type?
13.7.2.3  temp.deduct.guide 2707 tentatively ready Deduction guides cannot have a trailing requires-clause
13.7.5  temp.friend 1918 open friend templates with dependent scopes
13.7.5  temp.friend 1945 open Friend declarations naming members of class templates in non-templates
13.7.5  temp.friend 2118 open Stateful metaprogramming via friend injection
13.7.6  temp.spec.partial 708 open Partial specialization of member templates of class templates
13.7.6  temp.spec.partial 1647 drafting Type agreement of non-type template arguments in partial specializations
13.7.6  temp.spec.partial 2127 drafting Partial specialization and nullptr
13.7.6  temp.spec.partial 2173 open Partial specialization with non-deduced contexts
13.7.6.1  temp.spec.partial.general 2179 drafting Required diagnostic for partial specialization after first use
13.7.6.2  temp.spec.partial.match 549 drafting Non-deducible parameters in partial specializations
13.7.6.4  temp.spec.partial.member 1755 drafting Out-of-class partial specializations of member templates
13.7.7.2  temp.over.link 310 open Can function templates differing only in parameter cv-qualifiers be overloaded?
13.7.7.2  temp.over.link 2584 open Equivalent types in function template declarations
13.7.7.3  temp.func.order 402 open More on partial ordering of function templates
13.7.7.3  temp.func.order 1157 open Partial ordering of function templates is still underspecified
13.7.7.3  temp.func.order 2160 open Issues with partial ordering
13.7.8  temp.alias 1286 drafting Equivalence of alias templates
13.7.8  temp.alias 1430 open Pack expansion into fixed alias template parameter list
13.7.8  temp.alias 1554 drafting Access and alias templates
13.7.8  temp.alias 1979 drafting Alias template specialization in template member definition
13.7.8  temp.alias 1980 drafting Equivalent but not functionally-equivalent redeclarations
13.7.8  temp.alias 2236 drafting When is an alias template specialization dependent?
13.7.8  temp.alias 2794 open Uniqueness of lambdas in alias templates
13.8  temp.res 1257 open Instantiation via non-dependent references in uninstantiated templates
13.8  temp.res 2067 open Generated variadic templates requiring empty pack
13.8.1  temp.res.general 2462 drafting Problems with the omission of the typename keyword
13.8.1  temp.res.general 2468 drafting Omission of the typename keyword in a member template parameter list
13.8.1  temp.res.general 2746 open Checking of default template arguments
13.8.1  temp.res.general 2806 ready Make a type-requirement a type-only context
13.8.1  temp.res.general 2810 open Requiring the absence of diagnostics for templates
13.8.2  temp.local 186 open Name hiding and template template-parameters
13.8.2  temp.local 459 open Hiding of template parameters by base class members
13.8.3.2  temp.dep.type 1390 drafting Dependency of alias template specializations
13.8.3.2  temp.dep.type 1524 drafting Incompletely-defined class template base
13.8.3.2  temp.dep.type 1619 open Definition of current instantiation
13.8.3.2  temp.dep.type 2074 drafting Type-dependence of local class of function template
13.8.3.3  temp.dep.expr 2275 drafting Type-dependence of function template
13.8.3.3  temp.dep.expr 2487 drafting Type dependence of function-style cast to incomplete array type
13.8.3.3  temp.dep.expr 2600 ready Type dependency of placeholder types
13.8.3.3  temp.dep.expr 2785 ready Type-dependence of requires-expression
13.8.3.4  temp.dep.constexpr 2774 open Value-dependence of requires-expressions
13.8.3.5  temp.dep.temp 2090 drafting Dependency via non-dependent base class
13.8.4  temp.dep.res 2 drafting How can dependent names be used in member declarations that appear outside of the class template definition?
13.8.4.1  temp.point 287 drafting Order dependencies in template instantiation
13.8.4.1  temp.point 1845 drafting Point of instantiation of a variable template specialization
13.8.4.1  temp.point 2245 drafting Point of instantiation of incomplete class template
13.8.4.1  temp.point 2250 open Implicit instantiation, destruction, and TUs
13.8.4.1  temp.point 2497 drafting Points of instantiation for constexpr function templates
13.9  temp.spec 1253 open Generic non-template members
13.9  temp.spec 2435 open Alias template specializations
13.9.2  temp.inst 1602 review Linkage of specialization vs linkage of template arguments
13.9.2  temp.inst 1856 open Indirect nested classes of class templates
13.9.2  temp.inst 2202 drafting When does default argument instantiation occur?
13.9.2  temp.inst 2222 drafting Additional contexts where instantiation is not required
13.9.2  temp.inst 2263 drafting Default argument instantiation for friends
13.9.2  temp.inst 2265 drafting Delayed pack expansion and member redeclarations
13.9.2  temp.inst 2596 drafting Instantiation of constrained non-template friends
13.9.2  temp.inst 2808 review Explicit specialization of defaulted special member function
13.9.3  temp.explicit 293 open Syntax of explicit instantiation/specialization too permissive
13.9.3  temp.explicit 1046 open What is a “use” of a class specialization?
13.9.3  temp.explicit 1665 drafting Declaration matching in explicit instantiations
13.9.3  temp.explicit 2421 drafting Explicit instantiation of constrained member functions
13.9.3  temp.explicit 2501 drafting Explicit instantiation and trailing requires-clauses
13.9.4  temp.expl.spec 529 drafting Use of template<> with “explicitly-specialized” class templates
13.9.4  temp.expl.spec 1840 drafting Non-deleted explicit specialization of deleted function template
13.9.4  temp.expl.spec 1993 drafting Use of template<> defining member of explicit specialization
13.9.4  temp.expl.spec 2409 drafting Explicit specializations of constexpr static data members
13.10.2  temp.arg.explicit 264 open Unusable template constructors and conversion functions
13.10.2  temp.arg.explicit 2055 drafting Explicitly-specified non-deduced parameter packs
13.10.3  temp.deduct 697 open Deduction rules apply to more than functions
13.10.3  temp.deduct 1172 drafting “instantiation-dependent” constructs
13.10.3  temp.deduct 1322 drafting Function parameter type decay in templates
13.10.3  temp.deduct 1582 drafting Template default arguments and deduction failure
13.10.3  temp.deduct 1844 open Defining “immediate context”
13.10.3  temp.deduct 2054 ready Missing description of class SFINAE
13.10.3  temp.deduct 2296 open EWG Are default argument instantiation failures in the “immediate context”?
13.10.3.1  temp.deduct.general 2498 open Partial specialization failure and the immediate context
13.10.3.1  temp.deduct.general 2672 ready Lambda body SFINAE is still required, contrary to intent and note
13.10.3.1  temp.deduct.general 2769 open Substitution into template parameters and default template arguments should be interleaved
13.10.3.1  temp.deduct.general 2770 open Trailing requires-clause can refer to function parameters before they are substituted into
13.10.3.2  temp.deduct.call 503 open Cv-qualified function types in template argument deduction
13.10.3.2  temp.deduct.call 1513 drafting initializer_list deduction failure
13.10.3.2  temp.deduct.call 1584 drafting Deducing function types from cv-qualified types
13.10.3.2  temp.deduct.call 1939 open Argument conversions to nondeduced parameter types revisited
13.10.3.3  temp.deduct.funcaddr 1486 drafting Base-derived conversion in member pointer deduction
13.10.3.5  temp.deduct.partial 1221 open Partial ordering and reference collapsing
13.10.3.5  temp.deduct.partial 1610 drafting Cv-qualification in deduction of reference to array
13.10.3.6  temp.deduct.type 1763 open Length mismatch in template type deduction
13.10.3.6  temp.deduct.type 2328 drafting Unclear presentation style of template argument deduction rules
14.2  except.throw 2775 tentatively ready Unclear argument type for copy of exception object
14.4  except.handle 2172 drafting Multiple exceptions with one exception object
14.4  except.handle 2219 drafting Dynamically-unreachable handlers
14.5  except.spec 2417 open Explicit instantiation and exception specifications
15  cpp 2002 open WG14 White space within preprocessing directives
15.2  cpp.cond 925 open Type of character literals in preprocessor expressions
15.2  cpp.cond 1436 open Interaction of constant expression changes with preprocessor expressions
15.2  cpp.cond 2190 open Insufficient specification of __has_include
15.2  cpp.cond 2575 open SG12 Undefined behavior when macro-replacing "defined" operator
15.3  cpp.include 2576 open SG12 Undefined behavior with macro-expanded #include directives
15.6  cpp.replace 1718 drafting WG14 Macro invocation spanning end-of-file
15.6  cpp.replace 2003 drafting Zero-argument macros incorrectly specified
15.6.1  cpp.replace.general 2577 open SG12 Undefined behavior for preprocessing directives in macro arguments
15.6.3  cpp.stringize 1625 open WG14 Adding spaces between tokens in stringizing
15.6.3  cpp.stringize 1709 drafting Stringizing raw string literals containing newline
15.6.3  cpp.stringize 2578 open SG12 Undefined behavior when creating an invalid string literal via stringizing
15.6.4  cpp.concat 2522 open WG14 Removing placemarker tokens and retention of whitespace
15.6.4  cpp.concat 2579 open SG12 Undefined behavior when token pasting does not create a preprocessing token
15.6.5  cpp.rescan 268 open WG14 Macro name suppression in rescanned replacement text
15.7  cpp.line 2580 open SG12 Undefined behavior with #line
15.7  cpp.line 2693 open WG14 Escape sequences for the string-literal of #line
15.9  cpp.pragma 1889 drafting Unclear effect of #pragma on conformance
15.11  cpp.predefined 2581 open SG12 Undefined behavior for predefined macros
15.12  cpp.pragma.op 897 open _Pragma and extended string-literals
15.12  cpp.pragma.op 2694 open WG14 string-literals of the _Pragma operator
17.2.4  support.types.layout 2784 open EWG Unclear definition of member-designator for offsetof
17.13.3  csetjmp.syn 2361 open Unclear description of longjmp undefined behavior
Annex B  implimits 2181 drafting Normative requirements in an informative Annex
Annex C  diff 1944 open New C incompatibilities
C.6  diff.cpp03 1279 drafting Additional differences between C++ 2003 and C++ 2011
C.6.4  diff.cpp03.dcl.dcl 2772 ready Missing Annex C entry for linkage effects of linkage-specification
C.7  diff.iso 1248 open Updating Annex C to C99



Issues with "Ready" Status


1698. Files ending in \

Section: 5.2  [lex.phases]     Status: ready     Submitter: David Krauss     Date: 2013-06-10

The description of how to handle file not ending in a newline in 5.2 [lex.phases] paragraph 1, phase 2, is:

  1. Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines. Only the last backslash on any physical source line shall be eligible for being part of such a splice. If, as a result, a character sequence that matches the syntax of a universal-character-name is produced, the behavior is undefined. A source file that is not empty and that does not end in a new-line character, or that ends in a new-line character immediately preceded by a backslash character before any such splicing takes place, shall be processed as if an additional new-line character were appended to the file.

This is not clear regarding what happens if the last character in the file is a backslash. In such a case, presumably the result of adding the newline should not be a line splice but rather a backslash preprocessing-token (that will be diagnosed as an invalid token in phase 7), but that should be spelled out.

CWG 2023-07-14

Addressed by the resolution for issue 2747.




2747. Cannot depend on an already-deleted splice

Section: 5.2  [lex.phases]     Status: ready     Submitter: Jim X     Date: 2021-09-14

(From editorial issue 4903.)

Subclause 5.2 [lex.phases] paragraph 2 specifies:

... Each sequence of a backslash character (\) immediately followed by zero or more whitespace characters other than new-line followed by a new-line character is deleted, splicing physical source lines to form logical source lines. ... A source file that is not empty and that does not end in a new-line character, or that ends in a splice, shall be processed as if an additional new-line character were appended to the file.

This is confusing, because the first sentence deletes all splices, and then the last sentence checks for a splice that has already been deleted.

Proposed resolution (approved by CWG 2023-07-14):

Change in 5.2 [lex.phases] paragraph 2 as follows:

... Each sequence of a backslash character (\) immediately followed by zero or more whitespace characters other than new-line followed by a new-line character is deleted, splicing physical source lines to form logical source lines. ... A source file that is not empty and that (after splicing) does not end in a new-line character, or that ends in a splice, shall be processed as if an additional new-line character were appended to the file.

CWG 2023-07-14

CWG noted that a lone backslash at the end of a file remains (in the status quo and with the proposed change) and turns into an ill-formed preprocessing-token. The wording as amended seems sufficiently clear to consider issue 1698 resolved.




2764. Use of placeholders affecting name mangling

Section: 6.4.1  [basic.scope.scope]     Status: ready     Submitter: Hubert Tong     Date: 2023-07-05

Paper P2169R4 (A nice placeholder with no name), as approved by WG21 in Varna, added a placeholder facility. The intent was that the use of placeholders is sufficiently limited such that they never need to be mangled. Quote from 6.4.1 [basic.scope.scope] paragraph 5 as modified by the paper:

A declaration is name-independent if its name is _ and it declares a variable with automatic storage duration, a structured binding not inhabiting a namespace scope, the variable introduced by an init-capture, or a non-static data member.

The following example does not seem to follow that intent:

  struct A { A(); };
  inline void f() {
    static union { A _{}; };
    static union { A _{}; };
  }
  void g() { return f(); }

The preceding example needs handling similar to the following example, which is unrelated to the placeholder feature:

  struct A { A(); };
  inline void f() {
    { static union { A a{}; }; }
    { static union { A a{}; }; }
  }
  void g() { return f(); }

A similar problem may arise for static or thread_local structured bindings at block scope.

Finally, another example involving placeholders in anonymous unions:

  static union { int _ = 42; };
  int &ref = _;
  int foo() { return 13; }
  static union { int _ = foo(); };
  int main() { return ref; }

Possible resolution (reviewed by CWG 2023-08-25) [SUPERSEDED]:

Change in 6.4.1 [basic.scope.scope] paragraph 5 and add bullets as follows:

A class is name-dependent if it is an anonymous union declared at namespace scope or with a storage-class-specifier (11.5.2 [class.union.anon]). A declaration is name-independent if its name is _ and it declares

Proposed resolution (approved by CWG 2023-09-15):

Change in 6.4.1 [basic.scope.scope] paragraph 5 and add bullets as follows:

A declaration is name-independent if its name is _ and it declares



2793. Block-scope declaration conflicting with parameter name

Section: 6.4.3  [basic.scope.block]     Status: ready     Submitter: Jason Merrill     Date: 2023-08-31

Consider:

  void f(int i) { extern int i; } 

According to 6.4.3 [basic.scope.block] paragraph 2, the target scope of the declaration is relevant (which would be the global scope), but not the scope in which the name is bound. That seems wrong. For comparison, template parameter names use the latter rule (13.8.2 [temp.local] paragraph 6).

Proposed resolution (approved by CWG 2023-09-15):

If a declaration that is not a name-independent declaration and whose target scope is that binds a name in the block scope S of a potentially conflicts with a declaration whose target scope is the parent scope of S, the program is ill-formed.



2753. Storage reuse for string literal objects and backing arrays

Section: 6.7.2  [intro.object]     Status: ready     Submitter: Brian Bi     Date: 2023-06-29

Subclause 6.7.2 [intro.object] paragraph 9 specifies the general principle that two objects with overlapping lifetimes have non-overlapping storage, which can be observed by comparing addresses:

Unless an object is a bit-field or a subobject of zero size, the address of that object is the address of the first byte it occupies. Two objects with overlapping lifetimes that are not bit-fields may have the same address if one is nested within the other, or if at least one is a subobject of zero size and they are of different types; otherwise, they have distinct addresses and occupy disjoint bytes of storage.

After P2752, there are two exceptions: string literal objects and backing arrays for initializer lists.

Subclause 5.13.5 [lex.string] paragraph 9 specifies:

Evaluating a string-literal results in a string literal object with static storage duration (6.7.5 [basic.stc]). Whether all string-literals are distinct (that is, are stored in nonoverlapping objects) and whether successive evaluations of a string-literal yield the same or a different object is unspecified.

Subclause 9.4.4 [dcl.init.ref] paragraph 5, after application of P2752R3 (approved in June, 2023), specifies:

Whether all backing arrays are distinct (that is, are stored in non-overlapping objects) is unspecified.

It is unclear whether a backing array can overlap with a string literal object.

Furthermore, it is unclear whether any such object can overlap with named objects or temporaries, for example:

  const char (&r) [] = "foo";
  const char a[] = {'f', 'o', 'o', '\0'};

  int main() {  
    assert(&r == &a);   // allowed not to fail?
  }

Proposed resolution (approved by CWG 2023-11-09):

  1. Add a new paragraph before 6.7.2 [intro.object] paragraph 9 and change the latter as follows:

    An object is a potentially non-unique object if it is a string literal object (5.13.5 [lex.string]), the backing array of an initializer list (9.4.4 [dcl.init.ref]), or a subobject thereof.

    Unless an object is a bit-field or a subobject of zero size, the address of that object is the address of the first byte it occupies. Two objects with overlapping lifetimes that are not bit-fields may have the same address if one is nested within the other, or if at least one is a subobject of zero size and they are of different types, or if they are both potentially non-unique objects; otherwise, they have distinct addresses and occupy disjoint bytes of storage.

    [Example 2:

      static const char test1 = 'x';
      static const char test2 = 'x';
      const bool b = &test1 != &test2;  // always true
    
      static const char (&r) [] = "x";
      static const char *s = "x";  
      static std::initializer_list<char> il = { 'x' };
      const bool b2 = r != il.begin();        // unspecified result
      const bool b3 = r != s;                 // unspecified result
      const bool b4 = il.begin() != &test1;   // always true
      const bool b5 = r != &test1;            // always true
    

    -- end example]

  2. Change in subclause 5.13.5 [lex.string] paragraph 9 as follows:

    Evaluating a string-literal results in a string literal object with static storage duration (6.7.5 [basic.stc]). [ Note: String literal objects are potentially non-unique (6.7.2 [intro.object]). Whether all string-literals are distinct (that is, are stored in nonoverlapping objects) and whether successive evaluations of a string-literal yield the same or a different object is unspecified. -- end note ]
  3. Change in subclause 9.4.4 [dcl.init.ref] paragraph 5, after application of P2752R3 (approved in June, 2023), as follows:

    Whether all backing arrays are distinct (that is, are stored in non-overlapping objects) is unspecified. [ Note: Backing arrays are potentially non-unique objects (6.7.2 [intro.object]). -- end note ]

CWG 2023-07-14

CWG resolved that a named or temporary object is always disjoint from any other object, and thus cannot overlap with a string literal object or a backing array. The lines b4 and b5 in the example highlight that outcome.

Backing arrays and string literals can arbitrarily overlap among themselves; CWG believes the proposed wording achieves that outcome.

The ancillary question how address comparisons between potentially non-unique objects are treated during constant evaluation is handled in issue 2765.




2795. Overlapping empty subobjects with different cv-qualification

Section: 6.7.2  [intro.object]     Status: ready     Submitter: Jonathan Caves     Date: 2023-09-04

Subclause 6.7.2 [intro.object] paragraph 9 specifies:

... Two objects with overlapping lifetimes that are not bit-fields may have the same address if one is nested within the other, or if at least one is a subobject of zero size and they are of different types; otherwise, they have distinct addresses and occupy disjoint bytes of storage. [ Footnote: ... ]

Types T and const T are different types, but it is unlikely the rule is intending to differentiate along that line.

Suggested resolution [SUPERSEDED]:

Change in 6.7.2 [intro.object] paragraph 9 as follows:

... Two objects with overlapping lifetimes that are not bit-fields may have the same address if one is nested within the other, or if at least one is a subobject of zero size and they are of different types (ignoring top-level cv-qualifiers); otherwise, they have distinct addresses and occupy disjoint bytes of storage. [ Footnote: ... ]

Proposed resolution (approved by CWG 2023-09-15):

(Hypothetically, pointer-to-member types can be empty, but might differ in non-top-level cv-qualification.)

Change in 6.7.2 [intro.object] paragraph 9 as follows:

... Two objects with overlapping lifetimes that are not bit-fields may have the same address if one is nested within the other, or if at least one is a subobject of zero size and they are not of different similar types (7.3.6 [conv.qual]); otherwise, they have distinct addresses and occupy disjoint bytes of storage. [ Footnote: ... ]



2725. Overload resolution for non-call of class member access

Section: 7.6.1.5  [expr.ref]     Status: ready     Submitter: Richard Smith     Date: 2023-04-26

Consider:

  struct A {
    static void f();
    static void f(int);
  } x;
  void (*p)() = x.f;   // error

This is ill-formed as confirmed by issue 61. Various other changes (see issue 2241) have put the following example into the same category:

  struct B {
    static void f();
  } y;
  void (*q)() = y.f;   // error

If this is the intended outcome (although major implementations disagree), then the rules in 7.6.1.5 [expr.ref] should be clarified accordingly.

Proposed resolution (approved by CWG 2023-06-13):

Change in 7.6.1.5 [expr.ref] bullet 6.3 as follows:

This also addresses issue 1038.




2780. reinterpret_cast to reference to function types

Section: 7.6.1.10  [expr.reinterpret.cast]     Status: ready     Submitter: Lauri Vasama     Date: 2023-08-07

Subclause 7.6.1.10 [expr.reinterpret.cast] paragraph 11 specifies:

A glvalue of type T1, designating an object x, can be cast to the type “reference to T2” if an expression of type “pointer to T1” can be explicitly converted to the type “pointer to T2” using a reinterpret_cast. The result is that of *reinterpret_cast<T2 *>(p) where p is a pointer to x of type “pointer to T1”. No temporary is created, no copy is made, and no constructors (11.4.5 [class.ctor]) or conversion functions (11.4.8 [class.conv]) are called. [ Footnote: ... ]

The wording does not cover references to function type, only references to object types. All major implementations accept the following example:

  void f() {}

  void(&g())(int) {
    return reinterpret_cast<void(&)(int)>(f);
  }

Proposed resolution (approved by CWG 2023-09-15):

Change in 7.6.1.10 [expr.reinterpret.cast] paragraph 11 as follows:

A glvalue of type T1, designating an object or function x, can be cast to the type “reference to T2” if an expression of type “pointer to T1” can be explicitly converted to the type “pointer to T2” using a reinterpret_cast. The result is that of *reinterpret_cast<T2 *>(p) where p is a pointer to x of type “pointer to T1”. No temporary is created, no copy is made, and no constructors (11.4.5 [class.ctor]) or conversion functions (11.4.8 [class.conv]) are called. [ Footnote: ... ]



2823. Implicit undefined behavior when dereferencing pointers

Section: 7.6.2.2  [expr.unary.op]     Status: ready     Submitter: CWG     Date: 2023-11-06

Subclause 7.6.2.2 [expr.unary.op] paragraph 1 specifies:

The unary * operator performs indirection. Its operand shall be a prvalue of type “pointer to T”, where T is an object or function type. The operator yields an lvalue of type T denoting the object or function to which the operand points.

It is unclear what happens if the operand does not point to an object or function.

Proposed resolution (approved by CWG 2023-11-08):

Change in 7.6.2.2 [expr.unary.op] paragraph 1 as follows:

The unary * operator performs indirection. Its operand shall be a prvalue of type “pointer to T”, where T is an object or function type. The operator yields an lvalue of type T denoting the object or function to which the operand points. If the operand points to an object or function, the result denotes that object or function; otherwise, the behavior is undefined except as specified in 7.6.1.8 [expr.typeid].



2792. Clean up specification of noexcept operator

Section: 7.6.2.7  [expr.unary.noexcept]     Status: ready     Submitter: Jan Schultke     Date: 2023-08-30

The introductory sentence "can throw an exception" is misleading, because it might be interpreted to cover exceptions thrown as the result of encountering undefined behavior.

Proposed resolution (approved by CWG 2023-10-06):

Change all of 7.6.2.7 [expr.unary.noexcept] as follows:

The noexcept operator determines whether the evaluation of its operand, which is an unevaluated operand (7.2.3 [expr.context]), can throw an exception (14.2 [except.throw]).

noexcept-expression:
        noexcept ( expression )

The operand of the noexcept operator is an unevaluated operand (7.2.3 [expr.context]). If the operand is a prvalue, the temporary materialization conversion (7.3.5 [conv.rval]) is applied.

The result of the noexcept operator is a prvalue of type bool. The result is false if the full-expression of the operand is potentially-throwing (14.5 [except.spec]), and true otherwise.

[Note 1: A noexcept-expression is an integral constant expression (7.7 [expr.const]). —end note]

If the operand is a prvalue, the temporary materialization conversion (7.3.5 [conv.rval]) is applied. The result of the noexcept operator is true unless the full-expression of the operand is potentially-throwing (14.5 [except.spec]).




2102. Constructor checking in new-expression

Section: 7.6.2.8  [expr.new]     Status: ready     Submitter: Richard Smith     Date: 2015-03-16

According to 7.6.2.8 [expr.new] paragraph 25,

If the new-expression creates an object or an array of objects of class type, access and ambiguity control are done for the allocation function, the deallocation function (11.4.11 [class.free]), and the constructor (11.4.5 [class.ctor]).

The mention of “the constructor” here is strange. For the “object of class type” case, access and ambiguity control are done when we perform initialization in paragraph 17, and we might not be calling a constructor anyway (for aggregate initialization). This seems wrong.

For the “array of objects of class type” case, it makes slightly more sense (we need to check the trailing array elements can be default-initialized) but again (a) we aren't necessarily using a constructor, (b) we should say which constructor — and we may need overload resolution to find it, and (c) shouldn't this be part of initialization, so we can distinguish between the cases where we should copy-initialize from {} and the cases where we should default-initialize?

Additional notes (May, 2023):

It is unclear whether default-initialization is required to be well-formed even for an array with no elements.

Proposed resolution (approved by CWG 2023-06-16):

  1. Insert a new paragraph before 7.6.2.8 [expr.new] paragraph 9:

    If the allocated type is an array, the new-initializer is a braced-init-list, and the expression is potentially-evaluated and not a core constant expression, the semantic constraints of copy-initializing a hypothetical element of the array from an empty initializer list are checked (9.4.5 [dcl.init.list]). [ Note: The array can contain more elements than there are elements in the braced-init-list, requiring initialization of the remainder of the array elements from an empty initializer list. -- end note ]

    Objects created by a new-expression have dynamic storage duration (6.7.5.5 [basic.stc.dynamic]). ...

  2. Change in 7.6.2.8 [expr.new] paragraph 25 as follows:

    If the new-expression creates an object or an array of objects of class type, access and ambiguity control are done for the allocation function, the deallocation function (6.7.5.5.3 [basic.stc.dynamic.deallocation]), and the constructor (11.4.5 [class.ctor]) selected for the initialization (if any). If the new-expression creates an array of objects of class type, the destructor is potentially invoked (11.4.7 [class.dtor]).
  3. Change in 7.6.2.8 [expr.new] paragraph 28 as follows:

    A declaration of a placement deallocation function matches the declaration of a placement allocation function if it has the same number of parameters and, after parameter transformations (9.3.4.6 [dcl.fct]), all parameter types except the first are identical. If the lookup finds a single matching deallocation function, that function will be called; otherwise, no deallocation function will be called. If the lookup finds a usual deallocation function and that function, considered as a placement deallocation function, would have been selected as a match for the allocation function, the program is ill-formed. For a non-placement allocation function, the normal deallocation function lookup is used to find the matching deallocation function (7.6.2.9 [expr.delete]). In any case, the matching deallocation function (if any) shall be non-deleted and accessible from the point where the new-expression appears.
  4. Change in 9.4.1 [dcl.init.general] paragraph 7 as follows:

    To default-initialize an object of type T means:
    • ...
    • If T is an array type, the semantic constraints of default-initializing a hypothetical element shall be met and each element is default-initialized.
    • ...
  5. Change in 9.4.1 [dcl.init.general] paragraph 9 as follows:

    To value-initialize an object of type T means:
    • if If T is a (possibly cv-qualified) class type (Clause 11 [class]), then
      • if T has either no default constructor (11.4.5.2 [class.default.ctor]) or a default constructor that is user-provided or deleted, then the object is default-initialized;
      • otherwise, the object is zero-initialized and the semantic constraints for default-initialization are checked, and if T has a non-trivial default constructor, the object is default-initialized;.
    • if If T is an array type, the semantic constraints of value-initializing a hypothetical element shall be met and each element is value-initialized;.
    • otherwiseOtherwise, the object is zero-initialized.



2758. What is "access and ambiguity control"?

Section: 7.6.2.9  [expr.delete]     Status: ready     Submitter: CWG     Date: 2023-06-12

Subclause 7.6.2.9 [expr.delete] paragraph 12 specifies:

Access and ambiguity control are done for both the deallocation function and the destructor (11.4.7 [class.dtor], 11.4.11 [class.free]).

It is unclear what that means. In particular, ambiguity checking is part of overload resolution, and access checking requires a point of reference.

Proposed resolution (approved by CWG 2023-08-25):

  1. Change in 7.6.2.9 [expr.delete] paragraph 6 as follows:

    If the value of the operand of the delete-expression is not a null pointer value and the selected deallocation function (see below) is not a destroying operator delete, evaluating the delete-expression will invoke invokes the destructor (if any) for the object or the elements of the array being deleted. The destructor shall be accessible from the point where the delete-expression appears. In the case of an array, the elements will be are destroyed in order of decreasing address (that is, in reverse order of the completion of their constructor; see 11.9.3 [class.base.init]).
  2. Change in 7.6.2.9 [expr.delete] paragraph 10

    If more than one deallocation function is found, the The deallocation function to be called is selected as follows:
    • ...

    Unless the deallocation function is selected at the point of definition of the dynamic type's virtual destructor, the selected deallocation function shall be accessible from the point where the delete-expression appears.

  3. Remove 7.6.2.9 [expr.delete] paragraph 12:

    Access and ambiguity control are done for both the deallocation function and the destructor (11.4.7 [class.dtor], 11.4.11 [class.free]).



2749. Treatment of "pointer to void" for relational comparisons

Section: 7.6.9  [expr.rel]     Status: ready     Submitter: lprv     Date: 2023-03-12     Liaison: SG22

(From editorial issue 6173.)

Subclause 7.6.9 [expr.rel] paragraph 4 and paragraph 5 specify:

The result of comparing unequal pointers to objects [ Footnote: ] is defined in terms of a partial order consistent with the following rules: ...

[Note 1: A relational operator applied to unequal function pointers or to unequal pointers to void yields an unspecified result. -- end note]

Comparing pointers to objects that are stored in a variable of type "pointer to void" should be fine.

Proposed resolution (approved by CWG 2023-06-16):

Change in 7.6.9 [expr.rel] paragraph 4 and paragraph 5 as follows:

The result of comparing unequal pointers to objects [ Footnote: ... ] is defined in terms of a partial order consistent with the following rules: ...

[Note 1: A relational operator applied to unequal function pointers or to unequal pointers to void yields an unspecified result. A pointer value of type "pointer to cv void" can point to an object (6.8.4 [basic.compound]). -- end note]




2796. Function pointer conversions for relational operators

Section: 7.6.9  [expr.rel]     Status: ready     Submitter: Alisdair Meredith     Date: 2023-09-14

Consider:

  void f() {}
  void g() noexcept {}

  void q() {
    bool b1 = f == g;     // OK
    bool b2 = f > g;      // error: different types
  }

For the equality operators, 7.6.10 [expr.eq] paragraph 3 specifies:

If at least one of the operands is a pointer, pointer conversions (7.3.12 [conv.ptr]), function pointer conversions (7.3.14 [conv.fctptr]), and qualification conversions (7.3.6 [conv.qual]) are performed on both operands to bring them to their composite pointer type (7.2.2 [expr.type]). Comparing pointers is defined as follows: ...

In contrast, the corresponding rule for relational operators in 7.6.9 [expr.rel] paragraph 3 specifies:

The usual arithmetic conversions (7.4 [expr.arith.conv]) are performed on operands of arithmetic or enumeration type. If both operands are pointers, pointer conversions (7.3.12 [conv.ptr]) and qualification conversions (7.3.6 [conv.qual]) are performed to bring them to their composite pointer type (7.2.2 [expr.type]). After conversions, the operands shall have the same type.

However, all major implementations accept the example.

Proposed resolution (approved by CWG 2023-10-06):

Change in 7.6.9 [expr.rel] paragraph 3 as follows:

The usual arithmetic conversions (7.4 [expr.arith.conv]) are performed on operands of arithmetic or enumeration type. If both operands are pointers, pointer conversions (7.3.12 [conv.ptr]), function pointer conversions (7.3.14 [conv.fctptr]), and qualification conversions (7.3.6 [conv.qual]) are performed to bring them to their composite pointer type (7.2.2 [expr.type]). After conversions, the operands shall have the same type.



2768. Assignment to enumeration variable with a braced-init-list

Section: 7.6.19  [expr.ass]     Status: ready     Submitter: Shafik Yaghmour     Date: 2023-07-06

Consider:

   enum class E {E1};

   void f() {
     E e;
     e = E{0}; // #1
     e = {0};  // #2
   }

#1 first initializes a temporary of type E and then assigns that to e. For #2, 7.6.19 [expr.ass] bullet 8.1 specifies that #2 is equivalent to #1:

A braced-init-list may appear on the right-hand side of

However, there is no syntactic hint that #2 would invoke direct-initialization, and in fact gcc, icc, and MSVC reject #2, but clang accepts.

Proposed resolution (approved by CWG 2023-11-06):

Change in 7.6.19 [expr.ass] paragraph 8 as follows:

A braced-init-list B may appear on the right-hand side of



2755. Incorrect wording applied by P2738R1

Section: 7.7  [expr.const]     Status: ready     Submitter: Jens Maurer     Date: 2023-06-28

P2738R1 (constexpr cast from void*: towards constexpr type-erasure) applied incorrect wording to 7.7 [expr.const] bullet 5.14:

The issue is that T is defined to be a pointer type, but the "similar to" phrasing uses it as the pointee type.

Proposed resolution (approved by CWG 2023-07-14):

Change in 7.7 [expr.const] bullet 5.14 as follows:




2760. Defaulted constructor that is an immediate function

Section: 7.7  [expr.const]     Status: ready     Submitter: Corentin Jabot     Date: 2023-07-08

Consider:

  consteval int f(int);
  struct S {
   int x = f(0);
   S() = default;
  };

  int main() {
    S s;     // OK?
  }

Is S an immediate function?

The relevant specification is in 7.7 [expr.const] paragraph 18:

An immediate function is a function or constructor that is

Suggested resolution [SUPERSEDED]:

Change in 7.7 [expr.const] paragraph 18 as follows:

An immediate function is a function or constructor that is

Proposed resolution (approved by CWG 2023-08-25):

  1. Change in 7.7 [expr.const] paragraph 18 as follows:

    An immediate function is a function or constructor that is
    • declared with the consteval specifier, or
    • an immediate-escalating function F whose function body contains an immediate-escalating expression E such that E's innermost enclosing non-block scope is F's function parameter scope. [ Note: Default member initializers used to initialize a base or member subobject (11.9.3 [class.base.init]) are considered to be part of the function body (9.5.1 [dcl.fct.def.general]). -- end note ]
  2. Change in 9.5.1 [dcl.fct.def.general] paragraph 1 as follows:

    Any informal reference to the body of a function should be interpreted as a reference to the non-terminal function-body, including, for a constructor, default member initializers or default initialization used to initialize a base or member subobject in the absence of a mem-initializer-id (11.9.3 [class.base.init]).



2763. Ignorability of [[noreturn]] during constant evaluation

Section: 7.7  [expr.const]     Status: ready     Submitter: Jiang An     Date: 2023-07-10

Subclause 9.12.10 [dcl.attr.noreturn] paragraph 2 specifies:

If a function f is called where f was previously declared with the noreturn attribute and f eventually returns, the behavior is undefined.

Undefineed behavior is, in general, detected during constant evaluation, thus requiring an implementation to actually support the noreturn attribute, such as in the following example:

  [[noreturn]] constexpr void f() {}
  constexpr int x = (f(), 0);

It might be desirable to treat the assume and noreturn attributes alike in that regard.

Proposed resolution (approved by CWG 2023-07-14) [SUPERSEDED]:

Split into a separate paragraph and change 7.7 [expr.const] paragraph 5 as follows:

It is unspecified whether E is a core constant expression if E satisfies the constraints of a core constant expression, but evaluation of E would evaluate

CWG 2023-07-14

As an alternative, all of 9.12 [dcl.attr] could be added to the "library undefined behavior" bullet. However, CWG felt that a case-by-case consideration is warranted, given that assumptions set precedent in requiring special treatment.

Possible resolution (reviewed by CWG 2023-08-25) [SUPERSEDED]:

Split into a separate paragraph and change 7.7 [expr.const] paragraph 5 as follows:

It is unspecified whether E is a core constant expression if E satisfies the constraints of a core constant expression, but evaluation of E would evaluate

Proposed resolution (approved by CWG 2023-11-09):

Split into a separate paragraph and change 7.7 [expr.const] paragraph 5 as follows:

It is unspecified whether E is a core constant expression if E satisfies the constraints of a core constant expression, but evaluation of E would evaluate



2798. Manifestly constant evaluation of the static_assert message

Section: 7.7  [expr.const]     Status: ready     Submitter: Jason Merrill     Date: 2023-09-12

The message of a static_assert declaration is a conditional-expression and thus is not manifestly constant evaluated. Consider this example:

  struct X {
    std::string s;
    const char *p;
  };
  consteval X f() { return {.s = "some long string that requires a heap allocation", .p = "hello"}; }

  static_assert(cond, f().p);

The example is ill-formed, because the immediate invocation f() lets a pointer to the heap escape.

Proposed resolution (approved by CWG 2023-10-06):

  1. Change in 7.7 [expr.const] paragraph 19 as follows:

    [Note 11: Except for a static_assert-message, a A manifestly constant-evaluated expression is evaluated even in an unevaluated operand (7.2.3 [expr.context]). —end note]
  2. Change the grammar in 9.1 [dcl.pre] as follows:

    static_assert-message:
      unevaluated-string
      conditional-expression constant-expression
    
  3. Change in 9.1 [dcl.pre] bullet 11.2 as follows:

    • ...
    • if the static_assert-message is a conditional-expression constant-expression M, ...



2791. Unclear phrasing about "returning to the caller"

Section: 8.7.4  [stmt.return]     Status: ready     Submitter: Jan Schultke     Date: 2023-08-23

In 8.7.4 [stmt.return] and 8.7.5 [stmt.return.coroutine], the standard uses the phrasing "returns to its caller" when specifying return or co_return. It would be better to talk about transfer of control, which is a term used elsewhere in the standard.

Proposed resolution (approved by CWG 2023-10-06):

  1. Change in 7.6.2.4 [expr.await] paragraph 1 as follows:

    The co_await expression is used to suspend evaluation of a coroutine (9.5.4 [dcl.fct.def.coroutine]) while awaiting completion of the computation represented by the operand expression. Suspending the evaluation of a coroutine transfers control to its caller or resumer.
  2. Change 8.7.4 [stmt.return] paragraph 1 as follows:

    A function returns control to its caller by the return statement.
  3. Change 8.7.5 [stmt.return.coroutine] paragraph 1 as follows:

    A coroutine returns to its caller or resumer (9.5.4 [dcl.fct.def.coroutine]) by the co_return statement or when suspended (7.6.2.4 [expr.await]). A co_return statement transfers control to the caller or resumer of a coroutine (9.5.4 [dcl.fct.def.coroutine]). A coroutine shall not enclose a return statement (8.7.4 [stmt.return]).
  4. Change in 9.5.4 [dcl.fct.def.coroutine] paragraph 10 as follows:

    If the allocation function returns nullptr, the coroutine returns transfers control to the caller of the coroutine and the return value is obtained by a call to T::get_return_object_on_allocation_failure(), where T is the promise type.



2556. Unusable promise::return_void

Section: 8.7.5  [stmt.return.coroutine]     Status: ready     Submitter: Davis Herring     Date: 2022-03-24

Subclause 8.7.5 [stmt.return.coroutine] paragraph 3 specifies:

If p.return_void() is a valid expression, flowing off the end of a coroutine's function-body is equivalent to a co_return with no operand; otherwise flowing off the end of a coroutine's function-body results in undefined behavior.

However, 9.5.4 [dcl.fct.def.coroutine] paragraph 6 suggests:

If searches for the names return_void and return_value in the scope of the promise type each find any declarations, the program is ill-formed. [Note: If return_void is found, flowing off the end of a coroutine is equivalent to a co_return with no operand. Otherwise, flowing off the end of a coroutine results in undefined behavior (8.7.5 [stmt.return.coroutine]). —end note]

The difference is between the conditions "valid expression" and "found by name lookup". Effectively, it means that undefined behavior might result where the implementation could instead diagnose an ill-formed use of return_void (for example, because it is inaccessible, deleted, or the function call requires arguments).

Proposed resolution (approved by CWG 2023-06-17):

Change in 8.7.5 [stmt.return.coroutine] paragraph 3 as follows:

If p.return_void() is a valid expression a search for the name return_void in the scope of the promise type finds any declarations, flowing off the end of a coroutine's function-body is equivalent to a co_return with no operand; otherwise flowing off the end of a coroutine's function-body results in undefined behavior.



2531. Static data members redeclared as constexpr

Section: 9.2.6  [dcl.constexpr]     Status: ready     Submitter: Davis Herring     Date: 2022-02-16

C++17 made constexpr static data members implicitly inline (9.2.6 [dcl.constexpr] paragraph 1):

A function or static data member declared with the constexpr or consteval specifier is implicitly an inline function or variable (9.2.8 [dcl.inline]).

However, that makes the following well-formed C++14 program ill-formed, no diagnostic required, per 9.2.8 [dcl.inline] paragraph 5:

If a function or variable with external or module linkage is declared inline in one definition domain, an inline declaration of it shall be reachable from the end of every definition domain in which it is declared; no diagnostic is required.
  // x.hh
  struct X {
    static const int x;
  };

  // TU 1
  #include "x.hh"
  constexpr int X::x{};

  // TU 2
  #include "x.hh"
  int main() { return !&X::x; }

Proposed resolution (reviewed by CWG 2023-02-07, approved by CWG 2023-11-07):

Change 9.2.6 [dcl.constexpr] paragraph 1 as follows:

A function or static data member declared with the constexpr or consteval specifier on its first declaration is implicitly an inline function or variable (9.2.8 [dcl.inline]).

Drafting note: Functions must be declared constexpr on every declaration if on any, so this isn't a change for them.




2801. Reference binding with reference-related types

Section: 9.4.4  [dcl.init.ref]     Status: ready     Submitter: Brian Bi     Date: 2023-09-18

Consider:

  int* p;
  const int*&& r = static_cast<int*&&>(p);

The intent of core issues 2018 and 2352 was to make this example ill-formed, because it surprisingly introduces a temporary.

Proposed resolution (approved by CWG 2023-10-20):

Change in 9.4.4 [dcl.init.ref] bullet 5.4 as follows:




2252. Enumeration list-initialization from the same type

Section: 9.4.5  [dcl.init.list]     Status: ready     Submitter: Richard Smith     Date: 2016-03-22

According to 9.4.5 [dcl.init.list] bullet 3.8,

Otherwise, if T is an enumeration with a fixed underlying type (9.7.1 [dcl.enum]), the initializer-list has a single element v, and the initialization is direct-list-initialization, the object is initialized with the value T(v) (7.6.1.4 [expr.type.conv]); if a narrowing conversion is required to convert v to the underlying type of T , the program is ill-formed.

This could be read as requiring that there be a conversion from v to the underlying type of T, leaving the status of an example like the following unclear:

  enum class E {};
  struct X { operator E(); };
  E{X()}; // ok? 

Notes from the March, 2018 meeting:

CWG disagreed that the existing wording requires such a conversion, only that if such a conversion is possble, it must not narrow. A formulation along the lines of “if that initialization involves a narrowing conversion to the underlying type of T...” was suggested to clarify the intent. This will be handled editorially, and the issue will be left in "review" status until the change has been verified.

Additional notes (August, 2023)

Issue 2374 has meanwhile clarified that v is required to implicitly convert to the underlying type of the enumeration for 9.4.5 [dcl.init.list] bullet 3.8 to apply. Now, the logic falls through to 9.4.5 [dcl.init.list] bullet 3.9 for the above example, making it well-formed.

CWG 2023-09-15

Class types with conversions to scalar types were not in view when the wording in this bullet was conceived.

Proposed resolution (approved by CWG 2023-10-06):

Change in 9.4.5 [dcl.init.list] bullet 3.8 as follows:

Otherwise, if T is an enumeration with a fixed underlying type (9.7.1 [dcl.enum]) U, the initializer-list has a single element v of scalar type, v can be implicitly converted to U, and the initialization is direct-list-initialization, the object is initialized with the value T(v) (7.6.1.4 [expr.type.conv]); if a narrowing conversion is required to convert v to U, the program is ill-formed.



2570. Clarify constexpr for defaulted functions

Section: 9.5.2  [dcl.fct.def.default]     Status: ready     Submitter: Gabriel dos Reis     Date: 2022-04-18

After the application of P2448R2, 9.5.2 [dcl.fct.def.default] paragraph 3 reads:

A function explicitly defaulted on its first declaration is implicitly inline (9.2.8 [dcl.inline]), and is implicitly constexpr (9.2.6 [dcl.constexpr]) if it satisfies the requirements for a constexpr function.

It is unclear that no other such defaulted function is implicitly constexpr.

Proposed resolution (approved by CWG 2023-06-17):

A function explicitly defaulted on its first declaration is implicitly inline (9.2.8 [dcl.inline]), and is implicitly constexpr (9.2.6 [dcl.constexpr]) if it satisfies the requirements for a constexpr function. [Note: Other defaulted functions are not implicitly constexpr. -- end note ]



2754. Using *this in explicit object member functions that are coroutines

Section: 9.5.4  [dcl.fct.def.coroutine]     Status: ready     Submitter: Christof Meerwald     Date: 2023-06-23

Subclause 9.5.4 [dcl.fct.def.coroutine] paragraph 4 specifies:

In the following, pi is an lvalue of type Pi , where p1 denotes the object parameter and pi+1 denotes the ith non-object function parameter for a non-static member function, and pi denotes the ith function parameter otherwise. For a non-static member function, q1 is an lvalue that denotes *this; any other qi is an lvalue that denotes the parameter copy corresponding to pi , as described below.

An explicit object member function is a non-static member function, but there is no this.

Proposed resolution (approved by CWG 2023-07-14):

Change in 9.5.4 [dcl.fct.def.coroutine] paragraph 4 as follows:

In the following, pi is an lvalue of type Pi , where p1 denotes the object parameter and pi+1 denotes the ith non-object function parameter for a non-static an implicit object member function, and pi denotes the ith function parameter otherwise. For a non-static an implicit object member function, q1 is an lvalue that denotes *this; any other qi is an lvalue that denotes the parameter copy corresponding to pi, as described below.



2733. Applying [[maybe_unused]] to a label

Section: 9.12.8  [dcl.attr.unused]     Status: ready     Submitter: Barry Revzin     Date: 2023-05-25     Liaison: EWG

Subclause 9.12.8 [dcl.attr.unused] paragraph 2 specifies:

The attribute may be applied to the declaration of a class, a typedef-name, a variable (including a structured binding declaration), a non-static data member, a function, an enumeration, or an enumerator.

Absent from that list are labels, but both gcc and clang accept [[maybe_unused]] on a label, and behave accordingly.

Proposed resolution (approved by CWG 2023-07-14)

Change in 9.12.8 [dcl.attr.unused] as follows:

The attribute-token maybe_unused indicates that a name, label, or entity is possibly intentionally unused. No attribute-argument-clause shall be present.

The attribute may be applied to the declaration of a class, a typedef-name, a variable (including a structured binding declaration), a non-static data member, a function, an enumeration, or an enumerator, or to an identifier label (8.2 [stmt.label]).

A name or entity declared without the maybe_unused attribute can later be redeclared with the attribute and vice versa. An entity is considered marked after the first declaration that marks it.

Recommended practice: For an entity marked maybe_unused, implementations should not emit a warning that the entity or its structured bindings (if any) are used or unused. For a structured binding declaration not marked maybe_unused, implementations should not emit such a warning unless all of its structured bindings are unused. For a label to which maybe_unused is applied, implementations should not emit a warning that the label is used or unused.

[Example 1:
  [[maybe_unused]] void f([[maybe_unused]] bool thing1,
                          [[maybe_unused]] bool thing2) {
    [[maybe_unused]] bool b = thing1 && thing2;
    assert(b);
#ifdef NDEBUG
    goto x;
#endif
    [[maybe_unused]] x:
  }
Implementations should not warn that b or x is unused, whether or not NDEBUG is defined. — end example]

CWG 2023-07-14

CWG has reviewed and approved the proposed resolution. However, this is a new (albeit small) feature, thus forwarding to EWG via paper issue 1585 for approval.

EWG 2023-11-07

Accept the proposed resolution, forward to CWG for inclusion in C++26.




2783. Handling of deduction guides in global-module-fragment

Section: 10.4  [module.global.frag]     Status: ready     Submitter: Daniela Engert     Date: 2023-08-21

Consider:

  // header "S.h"
  
  template<class T>
  struct S {
    S(const T*);
  };
  template<class T>
  S(T*) -> S<T>

  // translation unit
  module;
  #include "S.h"

  export module M;
  export using ::S;

Obviously, the using-declaration referring to the class template S is exported by M, but what about the deduction guide of S?

Proposed resolution (approved by CWG 2023-08-25) [SUPERSEDED]:

Add a new bullet after 10.4 [module.global.frag] bullet 3.5.7 as follows:

Proposed resolution (approved by CWG 2023-10-06):

Add a new bullet after 10.4 [module.global.frag] bullet 3.5.7 as follows:




2759. [[no_unique_address] and common initial sequence

Section: 11.4.1  [class.mem.general]     Status: ready     Submitter: Richard Smith     Date: 2020-11-10

The interaction of [[no_unique_address]] and the definition of common initial sequence is still problematic. Subclause 11.4.1 [class.mem.general] bullet 23.3 specifies that corresponding members in a common initial sequence are not allowed to differ with respect to the presence or absence of a [[no_unique_address]] attribute. However, the Itanium ABI will not allocate two successive data members of the same empty class type at the same address, causing non-conforming behavior for the following example:

  struct A {};
  struct B {};

  struct C {
   [[no_unique_address]] A a;
   [[no_unique_address]] B b;
  };

  struct D {
   [[no_unique_address]] A a1;
   [[no_unique_address]] A a2;
  };

  static_assert(offsetof(C, b) == offsetof(D, a2));

See Itanium ABI issue 108.

Since "common initial sequence" and "layout compatible" are concepts mostly used for C compatibility, but [[no_unique_address]] does not exist in C, it seems reasonable to terminate a common initial sequence at the first data member that is declared [[no_unique_address]].

Another concern is the behavior of std::is_layout_compatible on implementations that ignore [[no_unique_address]]. On such an implementation, the following example would be considered layout-compatible, although it actually is not:

  struct E {};

  struct A {
    E e;
    int i;
  };

  struct B {
    [[no_unique_address]] E e;
    int i;
  };

  static_assert(
    std::is_layout_compatible_v<A, B>
  );

Alternative possible resolution [SUPERSEDED]:

Change in 11.4.1 [class.mem.general] paragraph 23 as follows:

The common initial sequence of two standard-layout struct (11.2 [class.prop]) types is the longest sequence of non-static data members and bit-fields in declaration order, starting with the first such entity in each of the structs, such that

Proposed resolution (approved by CWG 2023-08-25):

Change in 11.4.1 [class.mem.general] paragraph 23 as follows:

The common initial sequence of two standard-layout struct (11.2 [class.prop]) types is the longest sequence of non-static data members and bit-fields in declaration order, starting with the first such entity in each of the structs, such that



2595. "More constrained" for eligible special member functions

Section: 11.4.4  [special]     Status: ready     Submitter: Barry Revzin     Date: 2022-06-08

Consider:

  #include <type_traits>

  template<typename T>
  concept Int = std::is_same_v<T, int>;

  template<typename T>
  concept Float = std::is_same_v<T, float>;

  template<typename T>
  struct Foo {
    Foo() requires Int<T> = default; // #1
    Foo() requires Int<T> || Float<T> = default; // #2
  };

Per the wording, #1 is not eligible for Foo<float>, because the constraints are not satisfied. But #2 also is not eligible, because #1 is more constrained than #2. The intent is that #2 is eligible.

Proposed resolution (approved by CWG 2023-06-17):

Change in 11.4.4 [special] paragraph 6 as follows:

An eligible special member function is a special member function for which:



2761. Implicitly invoking the deleted destructor of an anonymous union member

Section: 11.4.7  [class.dtor]     Status: ready     Submitter: Corentin Jabot     Date: 2023-07-11

Consider:

  struct S{
    ~S() {}
  };

  struct A {
    union {
      S arr_;
    };
    ~A(); // user-provided!
  };

  auto foo() {
    return A{S()};
  }

Does the destructor of A attempt to destroy the (unnamed) data member that is the anonymous union? The latter has a deleted destructor per 11.4.7 [class.dtor]. For the default constructor, 11.9.3 [class.base.init] paragraph 9.2 prevents the corresponding construction.

Proposed resolution (approved by CWG 2023-08-25):

  1. Change in 9.4.2 [dcl.init.aggr] paragraph 9 as follows:

    The destructor for each element of class type other than an anonymous union member is potentially invoked (11.4.7 [class.dtor]) from the context where the aggregate initialization occurs
  2. Change in 11.4.7 [class.dtor] paragraph 13 as follows:

    After executing the body of the destructor and destroying any objects with automatic storage duration allocated within the body, a destructor for class X calls the destructors for X's direct non-variant non-static data members other than anonymous unions, the destructors for X's non-virtual direct base classes and, if X is the most derived class (11.9.3 [class.base.init]), its destructor calls the destructors for X's virtual base classes. All destructors are called as if they were referenced with a qualified name, that is, ignoring any possible virtual overriding destructors in more derived classes. Bases and members are destroyed in the reverse order of the completion of their constructor (see 11.9.3 [class.base.init]).
  3. Change in 14.3 [except.ctor] paragraph 3 as follows:

    A subobject is known to be initialized if it is not an anonymous union member and its initialization is specified
    • in 11.9.3 [class.base.init] for initialization by constructor,
    • in 11.4.5.3 [class.copy.ctor] for initialization by defaulted copy/move constructor,
    • in 11.9.4 [class.inhctor.init] for initialization by inherited constructor,
    • in 9.4.2 [dcl.init.aggr] for aggregate initialization,
    • in 7.5.5.3 [expr.prim.lambda.capture] for the initialization of the closure object when evaluating a lambda-expression,
    • in 9.4.1 [dcl.init.general] for default-initialization, value-initialization, or direct-initialization of an array.



2807. Destructors declared consteval

Section: 11.4.7  [class.dtor]     Status: ready     Submitter: Corentin Jabot     Date: 2023-09-07

There is a conflict between 9.2.6 [dcl.constexpr] paragraph 2

A destructor, an allocation function, or a deallocation function shall not be declared with the consteval specifier.

and 11.4.7 [class.dtor] paragraph 1

Each decl-specifier of the decl-specifier-seq of a prospective destructor declaration (if any) shall be friend, inline, virtual, constexpr, or consteval.

Proposed resolution (approved by CWG 2023-10-20):

Change in 11.4.7 [class.dtor] paragraph 1 as follows:

Each decl-specifier of the decl-specifier-seq of a prospective destructor declaration (if any) shall be friend, inline, virtual, or constexpr, or consteval.



2591. Implicit change of active union member for anonymous union in union

Section: 11.5.1  [class.union.general]     Status: ready     Submitter: Richard Smith     Date: 2022-05-29

Subclause 11.5.1 [class.union.general] paragraph 6 describes how union member subobjects are implicitly created by certain assignment operations that assign to union members. However, this description does not appear to properly handle the case of an anonymous union appearing within a union:

  union A {
    int x;
    union {
     int y;
    };
  };
  void f() {
    A a = {.x = 1};
    a.y = 2;
  }

Here, the expectation is that the assignment to a.y starts the lifetime of the anonymous union member subobject within A and also the int member subobject of the anonymous union member subobject. But the algorithm for computing S(a.y) determines that it is {a.y} and does not include the anonymous union member subobject.

Proposed resolution (approved by CWG 2023-06-17):

Change in 11.5.1 [class.union.general] paragraph 6 as follows:

In an assignment expression of the form E1 = E2 that uses either the built-in assignment operator (7.6.19 [expr.ass]) or a trivial assignment operator (11.4.6 [class.copy.assign]), for each element X of S(E1) and each anonymous union member X (11.5.2 [class.union.anon]) that is a member of a union and has such an element as an immediate subobject (recursively), if modification of X would have undefined behavior under 6.7.3 [basic.life], an object of the type of X is implicitly created in the nominated storage; no initialization is performed and the beginning of its lifetime is sequenced after the value computation of the left and right operands and before the assignment.

Editing note: Adding this rule into the definition of S would be more logical, but S(E) is a set of subexpressions of E and there is no form of expression that names an anonymous union member. Redefining S(E) to be a set of objects might be a better option.




2504. Inheriting constructors from virtual base classes

Section: 11.9.4  [class.inhctor.init]     Status: ready     Submitter: Hubert Tong     Date: 2021-11-03

According to 11.9.4 [class.inhctor.init] paragraph 1,

When a constructor for type B is invoked to initialize an object of a different type D (that is, when the constructor was inherited (9.9 [namespace.udecl])), initialization proceeds as if a defaulted default constructor were used to initialize the D object and each base class subobject from which the constructor was inherited, except that the B subobject is initialized by the invocation of the inherited constructor. The complete initialization is considered to be a single function call; in particular, the initialization of the inherited constructor's parameters is sequenced before the initialization of any part of the Dobject.

First, this assumes that the base class constructor will be invoked from the derived class constructor, which will not be true if the base is virtual and initialized by a more-derived constructor.

If the call to the virtual base constructor is omitted, the last sentence is unclear whether the initialization of the base class constructor's parameters by the inheriting constructor occurs or not. There is implementation divergence in the initialization of V's parameter in the following example:

  struct NonTriv {
    NonTriv(int);
    ~NonTriv();
  };
  struct V { V() = default; V(NonTriv); };
  struct Q { Q(); };
  struct A : virtual V, Q {
    using V::V;
    A() : A(42) { }
  };
  struct B : A { };
  void foo() { B b; }

CWG telecon 2022-09-23:

Inheriting constructors from a virtual base class ought to be ill-formed. Inform EWG accordingly.

Possible resolution [SUPERSEDED]:

  1. Change in 9.9 [namespace.udecl] paragraph 3 as follows:

    ... If a using-declarator names a constructor, its nested-name-specifier shall name a direct non-virtual base class of the current class. If the immediate (class) scope is associated with a class template, it shall derive from the specified base class or have at least one dependent base class.
  2. Change the example in 11.9.4 [class.inhctor.init] paragraph 1 as follows:

    D2 f(1.0);  // error: B1 has a deleted no default constructor
    
    struct W { W(int); };
    struct X : virtual W { using W::W; X() = delete; };
    struct Y : X { using X::X; };
    struct Z : Y, virtual W { using Y::Y; };
    Z z(0);  // OK, initialization of Y does not invoke default constructor of X
    
  3. Change the example in 11.9.4 [class.inhctor.init] paragraph 2 as follows:

    struct V1 : virtual B { using B::B; };
    struct V2 : virtual B { using B::B; };
    
    struct D2 : V1, V2 {
      using V1::V1;
      using V2::V2;
    };
    D1 d1(0);  // error: ambiguous
    D2 d2(0);  // OK, initializes virtual B base class, which initializes the A base class
               // then initializes the V1 and V2 base classes as if by a defaulted default constructor
    

CWG telecon 2022-10-07:

Given that there are examples that discuss inheriting constructors from virtual base classes and given the existing normative wording, making it clear that NonTriv is not constructed, CWG felt that the implementation divergence is best addressed by amending the examples.

Possible resolution [SUPERSEDED]:

Add another example before 11.9.4 [class.inhctor.init] paragraph 2 as follows:

[ Example:

struct NonTriv {
  NonTriv(int);
  ~NonTriv();
};
struct V { V() = default; V(NonTriv); };
struct Q { Q(); };
struct A : virtual V, Q {
  using V::V;
  A() : A(42) { }    // #1, A(42) is equivalent to V(42)
};
struct B : A { };
void foo() { B b; }

In this example, the V subobject of b is constructed using the defaulted default constructor. The mem-initializer naming the constructor inherited from V at #1 is not evaluated and thus no object of type NonTriv is constructed. -- end example ]

If the constructor was inherited from multiple base class subobjects of type B, the program is ill-formed.

Proposed resolution (approved by CWG 2023-11-06):

  1. Change in 11.9.4 [class.inhctor.init] paragraph 1 as follows:

    When a constructor for type B is invoked to initialize an object of a different type D (that is, when the constructor was inherited (9.9 [namespace.udecl])), initialization proceeds as if a defaulted default constructor were used to initialize the D object and each base class subobject from which the constructor was inherited, except that the B subobject is initialized by the invocation of the inherited constructor if the base class subobject were to be initialized as part of the D object (11.9.3 [class.base.init]). The invocation of the inherited constructor, including the evaluation of any arguments, is omitted if the B subobject is not to be initialized as part of the D object. The complete initialization is considered to be a single function call; in particular, unless omitted, the initialization of the inherited constructor's parameters is sequenced before the initialization of any part of the Dobject.
  2. Add another example before 11.9.4 [class.inhctor.init] paragraph 2 as follows:

    [ Example:

    struct V { V() = default; V(int); };
    struct Q { Q(); };
    struct A : virtual V, Q {
      using V::V;
      A() = delete;
    };
    int bar() { return 42; }
    struct B : A {
      B() : A(bar()) {}  // ok
    };
    struct C : B {};
    void foo() { C c; } // bar is not invoked, because the V subobject is not initialized as part of B
    

    -- end example ]

CWG telecon 2022-10-21:

This is an ABI break for implementations when transitioning to the C++17 model for inheriting constructors.




2762. Type of implicit object parameter

Section: 12.2.2.1  [over.match.funcs.general]     Status: ready     Submitter: Jim X     Date: 2023-07-11

Subclause 12.2.2.1 [over.match.funcs.general] paragraph 4 specifies:

For implicit object member functions, the type of the implicit object parameter is where X is the class of which the function is a member and cv is the cv-qualification on the member function declaration.

Since a member of some class C is also a member of any class derived from C, this specification is unclear.

Proposed resolution (approved by CWG 2023-08-25):

Change in 12.2.2.1 [over.match.funcs.general] paragraph 4 as follows:

For implicit object member functions, the type of the implicit object parameter is where X is the class of which the function is a direct member and cv is the cv-qualification on the member function declaration.



2628. Implicit deduction guides should propagate constraints

Section: 12.2.2.9  [over.match.class.deduct]     Status: ready     Submitter: Roy Jacobson     Date: 2022-09-11

Consider:

template<class T> concept True = true;

template<class T> struct X {
  template<class U> requires True<T> X(T, U(&)[3]);
};
template<typename T, typename U> X(T, U(&)[3]) -> X<T>;
int arr3[3];
X z(3, arr3);     // #1

According to 12.2.2.9 [over.match.class.deduct] bullet 1.1, the requires-clause of the constructor is not propagated to the function template synthesized for the implicit deduction guide. Thus, instead of favoring the more-constrained implicit deduction guide per 12.2.4.1 [over.match.best.general] bullet 2.6, the user-declared deduction-guide is preferred per 12.2.4.1 [over.match.best.general] bullet 2.11.

Proposed resolution (approved by CWG 2023-10-20):

Change in 12.2.2.9 [over.match.class.deduct] bullet 1.1 as follows:




2789. Overload resolution with implicit and explicit object member functions

Section: 12.2.4.1  [over.match.best.general]     Status: ready     Submitter: Corentin Jabot     Date: 2023-08-08

Consider:

  template <typename T = int>
  struct S {
    constexpr void f();                      // #1
    constexpr void f(this S&) requires true; // #2
  };

  void test() {
    S<> s;
    s.f();                 // #3
  }

With the current rules, the call at #3 is ambiguous, even though #2 is more constrainted.

Proposed resolution (approved by CWG 2023-11-07):

Change in 12.2.4.1 [over.match.best.general] bullet 2.6 as follows:




1038. Overload resolution of &x.static_func

Section: 12.3  [over.over]     Status: ready     Submitter: Mike Miller     Date: 2010-03-02

The Standard is not clear whether the following example is well-formed or not:

    struct S {
        static void f(int);
        static void f(double);
    };
    S s;
    void (*pf)(int) = &s.f;

According to 7.6.1.5 [expr.ref] bullet 4.3, you do function overload resolution to determine whether x.f is a static or non-static member function. 7.6.2.2 [expr.unary.op] paragraph 6 says that you can only take the address of an overloaded function in a context that determines the overload to be chosen, and the initialization of a function pointer is such a context (12.3 [over.over] paragraph 1) . The problem is that 12.3 [over.over] is phrased in terms of “an overloaded function name,” and this is a member access expression, not a name.

There is variability among implementations as to whether this example is accepted; some accept it as written, some only if the & is omitted, and some reject it in both forms.

Additional note (October, 2010):

A related question concerns an example like

    struct S {
        static void g(int*) {}
        static void g(long) {}
    } s;

    void foo() {
        (&s.g)(0L);
    }

Because the address occurs in a call context and not in one of the contexts mentioned in 12.3 [over.over] paragraph 1, the call expression in foo is presumably ill-formed. Contrast this with the similar example

    void g1(int*) {}
    void g1(long) {}

    void foo1() {
        (&g1)(0L);
    }

This call presumably is well-formed because 12.2.2.2 [over.match.call] applies to “the address of a set of overloaded functions.” (This was clearer in the wording prior to the resolution of issue 704: “...in this context using &F behaves the same as using the name F by itself.”) It's not clear that there's any reason to treat these two cases differently.

This question also bears on the original question of this issue, since the original wording of 12.2.2.2 [over.match.call] also described the case of an ordinary member function call like s.g(0L) as involving the “name” of the function, even though the postfix-expression is a member access expression and not a “name.” Perhaps the reference to “name” in 12.3 [over.over] should be similarly understood as applying to member access expressions?

Additional notes (February, 2023)

This appears to be resolved, in part by P1787R6 (accepted November, 2020).

CWG 2023-06-12

The clarifications in P1787R6 did not address the core of this issue, so it is kept open. In order to avoid confusion, a wording change to clarify the treatment (regardless of direction) seems advisable. CWG felt that the first and second examples should be treated consistently, and expressed a mild preferences towards making those ill-formed. It was noted that the reference to id-expression in 12.3 [over.over] can be understood to refer to the id-expression of a class member access.

This issue is resolved by issue 2725.




2806. Make a type-requirement a type-only context

Section: 13.8.1  [temp.res.general]     Status: ready     Submitter: Barry Revzin     Date: 2023-10-10

Consider:

  template <typename T>
  concept C = requires {
    typename T::type<void>;   // template required?
  };

There is implementation divergence: gcc accepts, clang and MSVC reject.

A type-requirement ought to be a type-only context.

Proposed resolution (approved by CWG 2023-10-20):

  1. Change in 7.5.7.3 [expr.prim.req.type] paragraph 1 as follows:

    A type-requirement asserts the validity of a type. The component names of a type-requirement are those of its nested-name-specifier (if any) and type-name. [Note 1: The enclosing requires-expression will evaluate to false if substitution of template arguments fails. —end note]
  2. Change in 13.8.1 [temp.res.general] paragraph 4 as follows:

    A qualified or unqualified name is said to be in a type-only context if it is the terminal name of
    • a typename-specifier, type-requirement, nested-name-specifier, elaborated-type-specifier, class-or-decltype, or
    • ...



2600. Type dependency of placeholder types

Section: 13.8.3.3  [temp.dep.expr]     Status: ready     Submitter: Hubert Tong     Date: 2022-06-18

Subclause 13.8.3.2 [temp.dep.type] paragraph 7 has a list of types considered to be dependent. This list covers placeholder types only insofar as it has an entry about decltype(expression). Subclause 13.8.3.3 [temp.dep.expr] paragraph 3 has a list of expression forms not considered dependent unless specific types named by the expressions are dependent. This list includes forms where placeholder types are allowed. For example, the wording does not say that the new-expression at #1 (below) is dependent, but it ought to be:

  template <typename T> struct A { A(bool, T); };

  void g(...);

  template <typename T>
  auto f(T t) { return g(new A(t, 0)); }  // #1

  int g(A<int> *);
  int h() { return f<void *>(nullptr); }

Some implementation even treats an obviously non-dependent case as dependent:

  template <typename T, typename U> struct A { A(T, U); };

  void g(...); // #1

  template <typename T>
  auto f() { return g(new A(0, 0)); } // #1 or #2?

  int g(A<int, int> *); // #2
  void h() { return f<void *>(); }

A similar example that is non-dependent:

  template <typename T, typename U = T> struct A { A(T, U); };

  void g(...);

  template <typename T>
  auto f() { return g(new A(0, 0)); }

  int g(A<int> *);
  void h() { return f<void *>(); }

And another non-dependent one:

  template <typename T, typename U = T> struct A { A(T); };

  void g(...);

  template <typename T>
  auto f() { return g(new A(0)); }

  int g(A<int> *);
  void h() { return f<void *>(); }

And here is an example that is dependent:

  template<class T>
  struct S {
   template<class U = T> struct A { A(int); };

   auto f() { return new A(0); } // dependent return type
  };

Proposed resolution (November, 2022) [SUPERSEDED]:

  1. Change in 7.6.2.8 [expr.new] paragraph 2 as follows:

    If a placeholder type (9.2.9.6 [dcl.spec.auto]) or a placeholder for a deduced class type (9.2.9.7 [dcl.type.class.deduct]) appears in the type-specifier-seq of a new-type-id or type-id of a new-expression, the allocated type is deduced as follows: Let init be the new-initializer , if any, and T be the new-type-id or type-id of the new-expression, then the allocated type is the type deduced for the variable x in the invented declaration (9.2.9.6 [dcl.spec.auto]):
    T x init ;
    
  2. Insert new paragraphs before 13.8.3.2 [temp.dep.type] paragraph 7 and change the latter as follows:

    An initializer is dependent if any constituent expression (6.9.1 [intro.execution]) of the initializer is type-dependent. A placeholder type (9.2.9.6.1 [dcl.spec.auto.general]) is dependent if it designates a type deduced from a dependent initializer.

    A placeholder for a deduced class type (9.2.9.7 [dcl.type.class.deduct]) is dependent if

    • it has a dependent initializer or
    • any default template-argument of the primary class template named by the placeholder is dependent when considered in the scope enclosing the primary class template.

    A type is dependent if it is

    • ...
    • a function type whose exception specification is value-dependent,
    • denoted by a dependent placeholder type,
    • denoted by a dependent placeholder for a deduced class type,
    • ...

Proposed resolution (approved by CWG 2023-06-12):

  1. Change in 7.6.2.8 [expr.new] paragraph 2 as follows:

    If a placeholder type (9.2.9.6 [dcl.spec.auto]) or a placeholder for a deduced class type (9.2.9.7 [dcl.type.class.deduct]) appears in the type-specifier-seq of a new-type-id or type-id of a new-expression, the allocated type is deduced as follows: Let init be the new-initializer , if any, and T be the new-type-id or type-id of the new-expression, then the allocated type is the type deduced for the variable x in the invented declaration (9.2.9.6 [dcl.spec.auto]):
    T x init ;
    
  2. Insert new paragraphs before 13.8.3.2 [temp.dep.type] paragraph 7 and change the latter as follows:

    An initializer is dependent if any constituent expression (6.9.1 [intro.execution]) of the initializer is type-dependent. A placeholder type (9.2.9.6.1 [dcl.spec.auto.general]) is dependent if it designates a type deduced from a dependent initializer.

    A placeholder for a deduced class type (9.2.9.7 [dcl.type.class.deduct]) is dependent if

    • it has a dependent initializer, or
    • it refers to an alias template that is a member of the current instantiation and whose defining-type-id is dependent after class template argument deduction (12.2.2.9 [over.match.class.deduct]) and substitution (13.7.8 [temp.alias]).

    [ Example:

      template<class T, class V>
      struct S { S(T); };
    
      template<class U>
      struct A {
        template<class T> using X = S<T, U>;
        template<class T> using Y = S<T, int>;
        void f() {
          new X(1);    // dependent
          new Y(1);    // not dependent
        }
      };
    

    -- end example ]

    A type is dependent if it is

    • ...
    • a function type whose exception specification is value-dependent,
    • denoted by a dependent placeholder type,
    • denoted by a dependent placeholder for a deduced class type,
    • ...



2785. Type-dependence of requires-expression

Section: 13.8.3.3  [temp.dep.expr]     Status: ready     Submitter: CWG     Date: 2023-07-17

(Split off from issue 2774.)

Subclause 13.8.3.3 [temp.dep.expr] is lacking specifiation about the type-dependence of requires-expressions.

Proposed resolution (approved by CWG 2023-08-25):

Change in 13.8.3.3 [temp.dep.expr] paragraph 4 as follows:

Expressions of the following forms are never type-dependent (because the type of the expression cannot be dependent):
  ...
  noexcept ( expression )
  requires-expression



2054. Missing description of class SFINAE

Section: 13.10.3  [temp.deduct]     Status: ready     Submitter: Ville Voutilainen     Date: 2014-12-07

Presumably something like the following should be well-formed, where a deduction failure in a partial specialization is handled as a SFINAE case as it is with function templates and not a hard error:

  template <class T, class U> struct X   {
    typedef char member;
  };

  template<class T> struct X<T,
   typename enable_if<(sizeof(T)>sizeof(
     float)), float>::type>
  {
    typedef long long member;
  };

  int main() {
    cout << sizeof(X<double, float>::member);
  }

However, this does not appear to be described anywhere in the Standard.

Additional notes (January, 2023)

The section on SFINAE (13.10.3.1 [temp.deduct.general] paragraph 8) is not specific to function templates, and 13.7.6.2 [temp.spec.partial.match] paragraph 2 hands off the "matching" determination for partial specializations to 13.10.3 [temp.deduct] in general. However, the definition of deduction substitution loci in 13.10.3.1 [temp.deduct.general] paragraph 7 does not account for the template argument list of a partial specialization.

Proposed resolution (approved by CWG 2023-11-08):

Change in 13.10.3.1 [temp.deduct.general] paragraph 7 as follows:

The deduction substitution loci are The substitution occurs in all types and expressions that are used in the deduction substitution loci. ...



2672. Lambda body SFINAE is still required, contrary to intent and note

Section: 13.10.3.1  [temp.deduct.general]     Status: ready     Submitter: Richard Smith     Date: 2022-09-30

Subclause 13.10.3.1 [temp.deduct.general] paragraph 9 specifies:

A lambda-expression appearing in a function type or a template parameter is not considered part of the immediate context for the purposes of template argument deduction. [Note 7: The intent is to avoid requiring implementations to deal with substitution failure involving arbitrary statements. ... -- end note ]

However, the intent of the note is not satisfied by the normative rule, because a lambda-expression appearing in a requires-expression has the same concerns as one in a function signature.

Suggested resolution: Change the rule to say that substitution into the body of a lambda is never in the immediate context of substitution into the lambda-expression and move the rule somewhere more general.

Possible resolution (reviewed by CWG 2023-08-25) [SUPERSEDED]:

  1. Change in 13.5.2.3 [temp.constr.atomic] paragraph 3 as follows:

    To determine if an atomic constraint is satisfied, the parameter mapping and template arguments are first substituted into its expression. If substitution results in an invalid type or expression in the immediate context of the atomic constraint (13.10.3.1 [temp.deduct.general]), the constraint is not satisfied. Otherwise, the lvalue-to-rvalue conversion (7.3.2 [conv.lval]) is performed if necessary, and E shall be a constant expression of type bool. The constraint is satisfied if and only if evaluation of E results in true.
  2. Change in 13.10.3.1 [temp.deduct.general] paragraph 9 as follows:

    A lambda-expression appearing in a function type or a template parameter Substituting into the body of a lambda-expression is not considered part of never in the immediate context for the purposes of template argument deduction of substitution into the lambda-expression. [Note 7: The intent is to avoid requiring implementations to deal with substitution failure involving arbitrary statements.

Proposed resolution (approved by CWG 2023-11-09):

  1. Change in 7.5.7.1 [expr.prim.req.general] paragraph 5 as follows:

    The substitution of template arguments into a requires-expression may can result in the formation of invalid types or expressions in the immediate context of its requirements (13.10.3.1 [temp.deduct.general]) or the violation of the semantic constraints of those requirements. In such cases, the requires-expression evaluates to false; it does not cause the program to be ill-formed. The substitution and semantic constraint checking proceeds in lexical order and stops when a condition that determines the result of the requires-expression is encountered. If substitution (if any) and semantic constraint checking succeed, the requires-expression evaluates to true.
  2. Change in 13.5.2.3 [temp.constr.atomic] paragraph 3 as follows:

    To determine if an atomic constraint is satisfied, the parameter mapping and template arguments are first substituted into its expression. If substitution results in an invalid type or expression in the immediate context of the atomic constraint (13.10.3.1 [temp.deduct.general]), the constraint is not satisfied. Otherwise, the lvalue-to-rvalue conversion (7.3.2 [conv.lval]) is performed if necessary, and E shall be a constant expression of type bool. The constraint is satisfied if and only if evaluation of E results in true.
  3. Change in 13.10.3.1 [temp.deduct.general] paragraph 9 as follows:

    A lambda-expression appearing in a function type or a template parameter is not considered part of the immediate context for the purposes of template argument deduction. When substituting into a lambda-expression, substitution into its body is not in the immediate context. [Note 7: The intent is to avoid requiring implementations to deal with substitution failure involving arbitrary statements.



2772. Missing Annex C entry for linkage effects of linkage-specification

Section: C.6.4  [diff.cpp03.dcl.dcl]     Status: ready     Submitter: Hubert Tong     Date: 2023-07-15

With C++11, anonymous namespaces changed from external linkage (with a unique namespace name) to internal linkage. That implies that extern "C", which affects names with external linkage only, no longer has an effect inside anonymous namespaces.

However, a corresponding Annex C entry is missing.

Proposed resolution (approved by CWG 2023-09-15):

Add a new paragraph in C.6.4 [diff.cpp03.dcl.dcl] as follows:

Affected subclause: 9.11 [dcl.link]
Change: Names declared in an anonymous namespace changed from external linkage to internal linkage; language linkage applies to names with external linkage only.
Rationale: Alignment with user expectations.
Effect on original feature: Valid C++ 2003 code may violate the one-definition rule (6.3 [basic.def.odr]) in this revision of C++. For example:
  namespace { extern "C" { extern int x; } }  // #1, previously external linkage and C language linkage, now internal linkage and C++ language linkage
  namespace A { extern "C" int x = 42; }      // #2, external linkage and C language linkage
  int main(void) { return x; }
This code is valid in C++ 2003, but #2 is not a definition for #1 in this revision of C++, violating the one-definition rule.





Issues with "Tentatively Ready" Status


2822. Side-effect-free pointer zap

Section: 6.7.5.1  [basic.stc.general]     Status: tentatively ready     Submitter: Davis Herring     Date: 2023-11-06

Subclause 6.7.5.1 [basic.stc.general] paragraph 4 seems to suggest that the end of duration of a region of storage causes actual modifications to pointer objects, causing questions about data races (in the abstract machine).

Proposed resolution (approved by CWG 2023-11-08):

  1. Append to 6.7.5.1 [basic.stc.general] paragraph 1:

    [ Note: After the duration of a region of storage has ended, the use of pointers to that region of storage is limited (6.8.4 [basic.compound]). -- end note ]
  2. Remove 6.7.5.1 [basic.stc.general] paragraph 4 as follows:

    When the end of the duration of a region of storage is reached, the values of all pointers representing the address of any part of that region of storage become invalid pointer values (6.8.4 [basic.compound]). Indirection through an invalid pointer value and passing an invalid pointer value to a deallocation function have undefined behavior. Any other use of an invalid pointer value has implementation-defined behavior. [ Footnote: ... ]
  3. Change in 6.8.4 [basic.compound] paragraph 3 as follows:

    [Note 2: A pointer past the end of an object (7.6.6 [expr.add]) is not considered to point to an unrelated object of the object's type, even if the unrelated object is located at that address. A pointer value becomes invalid when the storage it denotes reaches the end of its storage duration; see 6.7.5 [basic.stc].end note]
  4. Insert a new paragraph after 6.8.4 [basic.compound] paragraph 3:

    A pointer value P is valid in the context of an evaluation E if P is a null pointer value, or if it is a pointer to or past the end of an object O and E happens before the end of the duration of the region of storage for O. If a pointer value P is used in an evaluation E and P is not valid in the context of E, then the behavior is undefined if E is an indirection or an invocation of a deallocation function, and implementation-defined otherwise. [ Footnote: Some implementations might define that copying such a pointer value causes a system-generated runtime fault. -- end footnote ] [ Note: P can be valid in the context of E even if it points to a type unrelated to that of O or if O is not within its lifetime, although further restrictions apply to such pointer values (6.7.3 [basic.life], 7.2.1 [basic.lval], 7.6.6 [expr.add]). —end note]
  5. Change in 7.6.1.9 [expr.static.cast] paragraph 14 as follows:

    ... If the original pointer value represents the address A of a byte in memory and A does not satisfy the alignment requirement of T, then the resulting pointer value (6.8.4 [basic.compound]) is unspecified. ...
  6. Change in 7.6.1.10 [expr.reinterpret.cast] paragraph 5 as follows:

    A value of integral type or enumeration type can be explicitly converted to a pointer. A pointer converted to an integer of sufficient size (if any such exists on the implementation) and back to the same pointer type will have its original value (6.8.4 [basic.compound]); mappings between pointers and integers are otherwise implementation-defined.



2826. Missing definition of "temporary expression"

Section: 6.7.7  [class.temporary]     Status: tentatively ready     Submitter: Brian Bi     Date: 2022-12-16

The term "temporary expression" is used in 11.9.3 [class.base.init] paragraph 8 and 11.9.3 [class.base.init] paragraph 11, but is never defined.

Proposed resolution (approved by CWG 2023-11-10):

  1. Change in 6.7.7 [class.temporary] paragraph 6 as follows:

    The third context is when a reference binds to a temporary object. [ Footnote: ... ] The temporary object to which the reference is bound or the temporary object that is the complete object of a subobject to which the reference is bound persists for the lifetime of the reference if the glvalue to which the reference is bound was A temporary expression is a glvalue obtained through one of the following:
    • a temporary materialization conversion (7.3.5 [conv.rval]),
    • ( expression ), where expression is one of these expressions a temporary expression,
    • subscripting (7.6.1.2 [expr.sub]) of an array operand, where that operand is one of these expressions a temporary expression,
    • a class member access (7.6.1.5 [expr.ref]) using the . operator where the left operand is one of these expressions a temporary expression and the right operand designates a non-static data member of non-reference type,
    • a pointer-to-member operation (7.6.4 [expr.mptr.oper]) using the .* operator where the left operand is one of these expressions a temporary expression and the right operand is a pointer to data member of non-reference type,
    • a converting, without a user-defined conversion, a glvalue operand that is one of these expressions a temporary expression to a glvalue that refers to the object designated by the operand, or to its complete object or a subobject thereof,
    • a conditional expression (7.6.16 [expr.cond]) that is a glvalue where the second or third operand is one of these expressions a temporary expression, or
    • a comma expression (7.6.20 [expr.comma]) that is a glvalue where the right operand is one of these expressions a temporary expression.
    If a reference is bound to an object O that is the result of a temporary expression, the complete object of O persists for the lifetime of the reference.
  2. Change in 11.9.3 [class.base.init] paragraph 8 as follows:

    A temporary expression bound to Binding a reference member to an object that is the result of a temporary expression in a mem-initializer is ill-formed.
  3. Change in 11.9.3 [class.base.init] paragraph 11 as follows:

    A temporary expression bound to Binding a reference member to an object that is the result of a temporary expression from a default member initializer is ill-formed.



2560. Parameter type determination in a requirement-parameter-list

Section: 7.5.7.1  [expr.prim.req.general]     Status: tentatively ready     Submitter: Daveed Vandevoorde     Date: 2020-01-21     Liaison: EWG

Consider:

  template<typename T>
    requires requires (T p[10]) { (decltype(p))nullptr; }
  int v = 42;
  auto r = v<int>; // well-formed? 

This example is only well-formed if the type of the parameter p is adjusted to T*, but the provisions in 9.3.4.6 [dcl.fct] paragraph 5 cover function parameters only.

One option is to specify application of the same adjustments as for function parameters. Another option is to specify rules that arguably are more useful in a requires-expression.

Proposed resolution (approved by CWG 2023-11-07):

Change in 7.5.7.1 [expr.prim.req.general] paragraph 3 as follows:

A requires-expression may introduce local parameters using a parameter-declaration-clause (9.3.4.6 [dcl.fct]). A local parameter of a requires-expression shall not have a default argument. The type of such a parameter is determined as specified for a function parameter in 9.3.4.6 [dcl.fct]. These parameters have no linkage, storage, or lifetime; they are only used as notation for the purpose of defining requirements. The parameter-declaration-clause of a requirement-parameter-list shall not terminate with an ellipsis.
[Example 2:
  template<typename T>
  concept C = requires(T t, ...) {  // error: terminates with an ellipsis
    t;
  };
  template<typename T>
  concept C2 = requires(T p[2]) {
    (decltype(p))nullptr;           // OK, p has type "pointer to T"
  };
end example]

CWG 2023-06-17

There are arguments in favor of both options. Forwarded to EWG with paper issue 1582.

EWG 2023-11-07

Accept the proposed resolution and forward to CWG for inclusion in C++26.




1954. typeid null dereference check in subexpressions

Section: 7.6.1.8  [expr.typeid]     Status: tentatively ready     Submitter: David Majnemer     Date: 2014-06-23

According to 7.6.1.8 [expr.typeid] paragraph 2,

If the glvalue expression is obtained by applying the unary * operator to a pointer69 and the pointer is a null pointer value (7.3.12 [conv.ptr]), the typeid expression throws an exception (14.2 [except.throw]) of a type that would match a handler of type std::bad_typeid exception (17.7.5 [bad.typeid]).

The footnote makes clear that this requirement applies without regard to parentheses, but it is unspecified whether it applies when the dereference occurs in a subexpression of the operand (e.g., in the second operand of the comma operator or the second or third operand of a conditional operator). There is implementation divergence on this question.

Proposed resolution (approved by CWG 2023-11-09):

Insert a new paragraph before 7.6.1.8 [expr.typeid] paragraph 3 and change the latter as follows:

If an expression operand of typeid is a possibly-parenthesized unary-expression whose unary-operator is * and whose operand evaluates to a null pointer value (6.8.4 [basic.compound]), the typeid expression throws an exception (14.2 [except.throw]) of a type that would match a handler of type std::bad_typeid (17.7.5 [bad.typeid]). [ Note: In other contexts, evaluating such a unary-expression results in undefined behavior (7.6.2.2 [expr.unary.op]) -- end note ]

When typeid is applied to a glvalue whose type is a polymorphic class type (11.7.3 [class.virtual]), the result refers to a std::type_info object representing the type of the most derived object (6.7.2 [intro.object]) (that is, the dynamic type) to which the glvalue refers. If the glvalue is obtained by applying the unary * operator to a pointer [ Footnote: ... ] and the pointer is a null pointer value (6.8.4 [basic.compound]), the typeid expression throws an exception (14.2 [except.throw]) of a type that would match a handler of type std::bad_typeid exception (17.7.5 [bad.typeid]).




2668. co_await in a lambda-expression

Section: 7.6.2.4  [expr.await]     Status: tentatively ready     Submitter: Jim X     Date: 2022-12-12

Subclause 7.6.2.4 [expr.await] paragraph 2 disallows an await-expression to appear in the body of a lambda-expression:

An await-expression shall appear only in a potentially-evaluated expression within the compound-statement of a function-body outside of a handler (14.1 [except.pre]). ...

This is probably unintended.

Proposed resolution (approved by CWG 2023-11-11):

Change in 7.6.2.4 [expr.await] paragraph 2 as follows:

An await-expression shall appear only in as a potentially-evaluated expression within the compound-statement of a function-body or lambda-expression, in either case outside of a handler (14.1 [except.pre]). ...



2825. Range-based for statement using a braced-init-list

Section: 8.6.5  [stmt.ranged]     Status: tentatively ready     Submitter: Arthur O'Dwyer     Date: 2023-11-08     Liaison: EWG

Consider:

  for (int i : { 1, 2, 3 })  // argument-dependent lookup for begin(std::initializer_list<int>)
    /* ... */;

This is undesirable; instead, a member function begin should be preferred.

Proposed resolution (approved by CWG 2023-11-09):

Change in 8.6.5 [stmt.ranged] bullet 1.3 as follows:

begin-expr and end-expr are determined as follows:

Additional notes (November, 2023)

Forwarded to EWG via paper issue 1694 for confirmation of the design direction.

EWG 2023-11-09

Approved by EWG.




2634. Avoid circularity in specification of scope for friend class declarations

Section: 9.2.9.4  [dcl.type.elab]     Status: tentatively ready     Submitter: Jim X     Date: 2022-07-04

Consider:

auto f(struct X* ptr) {
  struct D {
    private:
      int d;
      friend class X;      // #1
  };
  return D{};
}
X* b = 0;
struct X {
  void show() {
    auto t = f(0);
    t.d = 10;              // #2 error: ::X is not a friend of f::D
  }
};

The target scope for #2 is f's block scope, making ::X not a friend of f::D. Thus the access at #2 is ill-formed. Clang disagrees.

Subclause 9.2.9.4 [dcl.type.elab] paragraph 3 specifies:

... If E contains an identifier but no nested-name-specifier and (unqualified) lookup for the identifier finds nothing, E shall not be introduced by the enum keyword and declares the identifier as a class-name. The target scope of E is the nearest enclosing namespace or block scope.

If an elaborated-type-specifier appears with the friend specifier as an entire member-declaration, the member-declaration shall have one of the following forms:

friend class-key nested-name-specifieropt identifier ;
...
Any unqualified lookup for the identifier (in the first case) does not consider scopes that contain the target scope; no name is bound.

This specification is circular in that the target scope that limits unqualified lookup is defined only if the identifier is actually declared, but the identifier is declared only if lookup finds nothing.

Proposed resolution (approved by CWG 2023-11-11):

Change in 9.2.9.4 [dcl.type.elab] paragraph 4 as follows:

... Any unqualified lookup for the identifier (in the first case) does not consider scopes that contain the target nearest enclosing namespace or block scope; no name is bound. [ Note: ... ]



2476. placeholder-type-specifiers and function declarators

Section: 9.2.9.6.1  [dcl.spec.auto.general]     Status: tentatively ready     Submitter: Davis Herring     Date: 2021-01-29

According to 9.2.9.6.1 [dcl.spec.auto.general] paragraph 3,

The placeholder type can appear with a function declarator in the decl-specifier-seq, type-specifier-seq, conversion-function-id, or trailing-return-type, in any context where such a declarator is valid. If the function declarator includes a trailing-return-type (9.3.4.6 [dcl.fct]), that trailing-return-type specifies the declared return type of the function. Otherwise, the function declarator shall declare a function.

This wording disallows a declaration like

   int f();
   auto (*fp)()=f;

The requirement to declare a function was introduced by the resolution of issue 1892.

Proposed resolution (April, 2021) [SUPERSEDED]:

Change 9.2.9.6.1 [dcl.spec.auto.general] paragraph 3 as follows:

The placeholder type can appear with a function declarator in the decl-specifier-seq, type-specifier-seq, conversion-function-id, or trailing-return-type, in any context where such a declarator is valid if the function declarator includes a trailing-return-type T (9.3.4.6 [dcl.fct]) or declares a function. If the function declarator includes a trailing-return-type (9.3.4.6 [dcl.fct]), that trailing-return-type specifies In the former case, T is the declared return type of the function. Otherwise, the function declarator shall declare a function. If the declared return type of the a function contains a placeholder type, the return type of the function is deduced from non-discarded return statements, if any, in the body of the function (8.5.2 [stmt.if]).

Additional notes (May, 2021):

It was observed that the proposed resolution above does not address the example in the issue, since fp neither has a trailing-return-type nor declares a function. Presumably another case in which a function declarator with a placeholder return type should be permitted is in the declaration of a variable in which the type is deduced from its initializer.

It was also noted in passing that the deduction in the example is only partial: the parameter-type-list is specified by the declarator and only the return type is deduced from the initializer. Although this example is supported by current implementations, there is implementation divergence in the support of another case in which only part of the variable's type is deduced:

    auto (&ar)[2] = L"a";  // Array bound declared, element type deduced

This issue is related to issue 1892, which prohibited cases like

    std::vector<auto(*)()> v;

The ultimate outcome of the two issues should be:

    int f();
    auto (*fp1)() = f;       // OK
    auto (*fp2)()->int = f;  // OK
    auto (*fp3)()->auto = f; // OK

    template<typename T> struct C { };
    C<auto(*)()> c1;         // Not OK
    C<auto(*)()->int> c2;    // OK
    C<auto(*)()->auto> c3;   // Not OK

Proposed resolution (January, 2023) [SUPERSEDED]:

  1. Change in 9.2.9.6.1 [dcl.spec.auto.general] paragraph 1 as follows:

    A placeholder-type-specifier designates a placeholder type that will be replaced later, typically by deduction from an initializer.
  2. Change and split 9.2.9.6.1 [dcl.spec.auto.general] paragraph 3 as follows:

    A placeholder type can appear with a function declarator in the decl-specifier-seq, type-specifier-seq, conversion-function-id, or trailing-return-type, in any context where such for a function declarator is valid that includes a trailing-return-type (9.3.4.6 [dcl.fct]). If the function declarator includes a trailing-return-type (9.3.4.6 [dcl.fct]), that trailing-return-type specifies the declared return type of the function.

    Otherwise, the A placeholder type can appear in the decl-specifier-seq or type-specifier-seq in the declared return type of a function declarator shall declare that declares a function. If the declared return type of the function contains a placeholder type, ; the return type of the function is deduced from non-discarded return statements, if any, in the body of the function (8.5.2 [stmt.if]).

  3. Change in 9.2.9.6.1 [dcl.spec.auto.general] paragraph 4 as follows:

    The type of a variable declared using a placeholder type is deduced from its initializer. This use is allowed in an initializing declaration (9.4 [dcl.init]) of a variable. The placeholder type shall appear as one of the decl-specifiers in the decl-specifier-seq and or as one of the type-specifiers in a trailing-return-type that specifies the type that replaces such a decl-specifier; the decl-specifier-seq shall be followed by one or more declarators, each of which shall be followed by a non-empty initializer. [ Example:
      ...
      auto f() -> int;                // OK, f returns int
      auto (*fp)() -> auto = f;       // OK
      ...
    
    -- end example ]
  4. Change in 9.3.4.6 [dcl.fct] paragraph 1 as follows:

    In a declaration T D where D has the form
    D1 ( parameter-declaration-clause ) cv-qualifier-seqopt
      ref-qualifieropt noexcept-specifieropt attribute-specifier-seqopt trailing-return-typeopt
    
    and the type of the contained declarator-id in the declaration T D1 is "derived-declarator-type-list T",:
    • If the trailing-return-type is present, T shall be the single type-specifier auto, and the declared return type of the function type is the type specified by the trailing-return-type.
    • Otherwise, the declared return type of the function type is T.
    theThe type of the declarator-id in D is "derived-declarator-type-list noexceptopt function of parameter-type-list cv-qualifier-seqopt ref-qualifieropt returning T U", where
    • the parameter-type-list is derived from the parameter-declaration-clause as described below,
    • U is the declared return type, and
    • the optional noexcept is present if and only if the exception specification (14.5 [except.spec]) is non-throwing.
    The optional attribute-specifier-seq appertains to the function type.
  5. Remove 9.3.4.6 [dcl.fct] paragraph 2:

    In a declaration T D where D has the form
    D1 ( parameter-declaration-clause ) cv-qualifier-seqopt
      ref-qualifieropt noexcept-specifieropt attribute-specifier-seqopt trailing-return-type
    
    and the type ... The optional attribute-specifier-seq appertains to the function type.
  6. Change in 11.4.8.3 [class.conv.fct] paragraph 1 as follows:

    A declaration whose declarator-id has an unqualified-id that is a conversion-function-id declares a conversion function; its declarator shall be a function declarator (9.3.4.6 [dcl.fct]) of the form
    ptr-declarator noptr-declarator ( parameter-declaration-clause ) cv-qualifier-seqopt
          ref-qualifier-seqopt noexcept-specifieropt attribute-specifier-seqopt parameters-and-qualifiers
    
    where the ptr-declarator noptr-declarator consists solely of an id-expression, an optional attribute-specifier-seq, and optional surrounding parentheses, and the id-expression has one of the following forms: ...
  7. Change in 11.4.8.3 [class.conv.fct] paragraph 2 as follows:

    A conversion function shall have no non-object parameters and shall be a non-static member function of a class or class template X; its declared return type is the conversion-type-id and it specifies a conversion from X to the type specified by the conversion-type-id interpreted as a type-id (9.3.2 [dcl.name]). A decl-specifier in the decl-specifier-seq of a conversion function (if any) shall not be a defining-type-specifier .
  8. Remove 11.4.8.3 [class.conv.fct] paragraph 3:

    The type of the conversion function is “noexceptopt function taking no parameter cv-qualifier-seq opt ref-qualifier opt returning conversion-type-id”.

CWG 2023-06

This does not address void f2(auto (*)() -> auto);

Proposed resolution (approved by CWG 2023-11-10):

  1. Change in 9.2.9.6.1 [dcl.spec.auto.general] paragraph 1 as follows:

    A placeholder-type-specifier designates a placeholder type that will be replaced later, typically by deduction from an initializer.
  2. Change 9.2.9.6.1 [dcl.spec.auto.general] paragraph 2 as follows:

    A The type of a parameter-declaration of a function declaration (9.3.4.6 [dcl.fct]), lambda-expression (7.5.5 [expr.prim.lambda]), or template-parameter (13.2 [temp.param]) can be declared using a placeholder-type-specifier of the form type-constraintopt auto can be used as a decl-specifier of the decl-specifier-seq of a parameter-declaration of a function declaration or lambda-expression and, if it is not the auto type-specifier introducing. The placeholder type shall appear as one of the decl-specifiers in the decl-specifier-seq or as one of the type-specifiers in a trailing-return-type , that specifies the type that replaces such a decl-specifier (see below); the placeholder type is a generic parameter type placeholder of the function declaration or, lambda-expression, or template-parameter, respectively.
  3. Change and split 9.2.9.6.1 [dcl.spec.auto.general] paragraph 3 as follows:

    A placeholder type can appear with a function declarator in the decl-specifier-seq, type-specifier-seq, conversion-function-id, or trailing-return-type, in any context where such for a function declarator is valid that includes a trailing-return-type (9.3.4.6 [dcl.fct]). If the function declarator includes a trailing-return-type (9.3.4.6 [dcl.fct]), that trailing-return-type specifies the declared return type of the function.

    Otherwise, the A placeholder type can appear in the decl-specifier-seq or type-specifier-seq in the declared return type of a function declarator shall declare that declares a function. If the declared return type of the function contains a placeholder type, ; the return type of the function is deduced from non-discarded return statements, if any, in the body of the function (8.5.2 [stmt.if]).

  4. Change in 9.2.9.6.1 [dcl.spec.auto.general] paragraph 4 as follows:

    The type of a variable declared using a placeholder type is deduced from its initializer. This use is allowed in an initializing declaration (9.4 [dcl.init]) of a variable. The placeholder type shall appear as one of the decl-specifiers in the decl-specifier-seq and or as one of the type-specifiers in a trailing-return-type that specifies the type that replaces such a decl-specifier; the decl-specifier-seq shall be followed by one or more declarators, each of which shall be followed by a non-empty initializer. [ Example:
      ...
      auto f() -> int;                // OK, f returns int
      auto (*fp)() -> auto = f;       // OK
      ...
    
    -- end example ]
  5. Change and split 9.2.9.6.1 [dcl.spec.auto.general] paragraph 5 as follows:

    A placeholder type can also be used in the type-specifier-seq in of the new-type-id or in the type-id of a new-expression (7.6.2.8 [expr.new]) and as a decl-specifier of the parameter-declaration's decl-specifier-seq in a template-parameter (13.2 [temp.param]). In such a type-id, the placeholder type shall appear as one of the type-specifiers in the type-specifier-seq or as one of the type-specifiers in a trailing-return-type that specifies the type that replaces such a type-specifier.

    The auto type-specifier can also be used as the simple-type-specifier in an explicit type conversion (functional notation) (7.6.1.4 [expr.type.conv]).

  6. Change in 9.3.4.6 [dcl.fct] paragraph 1 as follows:

    In a declaration T D where T may be empty and D has the form
    D1 ( parameter-declaration-clause ) cv-qualifier-seqopt
      ref-qualifieropt noexcept-specifieropt attribute-specifier-seqopt trailing-return-typeopt
    
    a derived-declarator-type-list is determined as follows: and
    • If the unqualified-id of the declarator-id is a conversion-function-id, the derived-declarator-type-list is empty.
    • Otherwise, the derived-declarator-type-list is as appears in the type "derived-declarator-type-list T" of the contained declarator-id in the declaration T D1 is "derived-declarator-type-list T".
    The declared return type U of the function type is determined as follows:
    • If the trailing-return-type is present, T shall be the single type-specifier auto, and U is the type specified by the trailing-return-type.
    • Otherwise, if the declaration declares a conversion function, see 11.4.8.3 [class.conv.fct].
    • Otherwise, U is T.
    theThe type of the declarator-id in D is "derived-declarator-type-list noexceptopt function of parameter-type-list cv-qualifier-seqopt ref-qualifieropt returning T U", where
    • the parameter-type-list is derived from the parameter-declaration-clause as described below and
    • the optional noexcept is present if and only if the exception specification (14.5 [except.spec]) is non-throwing.
    The optional attribute-specifier-seq appertains to the function type.
  7. Remove 9.3.4.6 [dcl.fct] paragraph 2:

    In a declaration T D where D has the form
    D1 ( parameter-declaration-clause ) cv-qualifier-seqopt
      ref-qualifieropt noexcept-specifieropt attribute-specifier-seqopt trailing-return-type
    
    and the type ... The optional attribute-specifier-seq appertains to the function type.
  8. Change in 11.4.8.3 [class.conv.fct] paragraph 1 as follows:

    A declaration whose declarator-id has an unqualified-id that is a conversion-function-id declares a conversion function; its declarator shall be a function declarator (9.3.4.6 [dcl.fct]) of the form
    ptr-declarator noptr-declarator ( parameter-declaration-clause ) cv-qualifier-seqopt
          ref-qualifier-seqopt noexcept-specifieropt attribute-specifier-seqopt parameters-and-qualifiers
    
    where the ptr-declarator noptr-declarator consists solely of an id-expression, an optional attribute-specifier-seq, and optional surrounding parentheses, and the id-expression has one of the following forms: ...
  9. Change in 11.4.8.3 [class.conv.fct] paragraph 2 as follows:

    A conversion function shall have no non-object parameters and shall be a non-static member function of a class or class template X; its declared return type is the conversion-type-id and it specifies a conversion from X to the type specified by the conversion-type-id interpreted as a type-id (9.3.2 [dcl.name]). A decl-specifier in the decl-specifier-seq of a conversion function (if any) shall not be a defining-type-specifier .
  10. Remove 11.4.8.3 [class.conv.fct] paragraph 3:

    The type of the conversion function is “noexceptopt function taking no parameter cv-qualifier-seq opt ref-qualifier opt returning conversion-type-id”.



2824. Copy-initialization of arrays

Section: 9.4.1  [dcl.init.general]     Status: tentatively ready     Submitter: Anoop Rana     Date: 2023-11-06

Consider:

  std::string arr[] = "some string";

Prior to the application of paper P0960R3 (Allow initializing aggregates from a parenthesized list of values), this was ill-formed, but now it is well-formed. However, the specification talks about an expression-list as part of the initializer, which does not exist in this case.

Proposed resolution (approved by CWG 2023-11-07):

Change in 9.4.1 [dcl.init.general] bullet 16.5 as follows:

Otherwise, if the destination type is an array, the object is initialized as follows. The initializer shall be of the form ( expression-list ). Let x1 , . . . , xk be the elements of the expression-list. If the destination type is an array of unknown bound, it is defined as having k elements. Let n denote the array size after this potential adjustment. If k is greater than n, the program is ill-formed. Otherwise, ...



2657. Cv-qualification adjustment when binding reference to temporary

Section: 9.4.4  [dcl.init.ref]     Status: tentatively ready     Submitter: Brian Bi     Date: 2022-11-10

Core issue 2481 was resolved by clarifying that the temporary object in p5.4.2 is cv-qualified if the reference being initialized is cv-qualified. However, this is not the right bullet point for the example given,

  constexpr const int &r = 42;

Such an initialization would actually use bullet 5.3.1 instead. (5.4.2 would be used if the initializer were, for example, 3.14.) We therefore need to make a similar clarification in bullet 5.3, and ideally using the same language.

Proposed resolution (approved by CWG 2023-11-11):

  1. Change in 9.4.4 [dcl.init.ref] bullet 5.3 as follows:

    Otherwise, if the initializer expression
    • is an rvalue (but not a bit-field) or function lvalue and “cv1 T1” is reference-compatible with “cv2 T2”, or
    • has a class type (i.e., T2 is a class type), where T1 is not reference-related to T2, and can be converted to an rvalue or function lvalue of type “cv3 T3”, where “cv1 T1” is reference-compatible with “cv3 T3” (see 12.2.2.7 [over.match.ref]),
    then the initializer expression in the first case and the converted expression in the second case is called the converted initializer. If the converted initializer is a prvalue, let its type be denoted by T4; the temporary materialization conversion (7.3.5 [conv.rval]) is applied, considering the type of the prvalue to be is adjusted to type “cv1 T4” (7.3.6 [conv.qual]) and the temporary materialization conversion (7.3.5 [conv.rval]) is applied. In any case, the reference binds to the resulting glvalue (or to an appropriate base class subobject).
  2. Append to the example in 9.4.4 [dcl.init.ref] bullet 5.3 as follows:

      B&& rrb = x;  // binds directly to the result of operator B
      const int& r2 = 0;  // binds directly to temporary of type const int
    
  3. Change the example in 9.4.4 [dcl.init.ref] bullet 5.4 as follows:

      const double& rcd2 = 2;   // rcd2 refers to temporary with type const double and value 2.0
    



2638. Improve the example for initializing by initializer list

Section: 9.4.5  [dcl.init.list]     Status: tentatively ready     Submitter: Shafik Yaghmour     Date: 2022-10-26

Issue 2137 amended the rules for initialization by initializer list, but neglected to add an example.

Proposed resolution (approved by CWG 2023-11-11):

Change the example in 9.4.5 [dcl.init.list] bullet 3.7 as follows:

struct S {
  S(std::initializer_list<double>); // #1
  S(std::initializer_list<int>);    // #2
  S(std::initializer_list<S>);      // #3
  S();                              // #3#4

  // ...
};
S s1 = { 1.0, 2.0, 3.0 };  // invoke #1
S s2 = { 1, 2, 3 };        // invoke #2
S s3{s2};                  // invoke #3 and not the copy constructor
S s3s4 = { };              // invoke #3#4



2637. Injected-class-name as a simple-template-id

Section: 11.1  [class.pre]     Status: tentatively ready     Submitter: Shafik Yaghmour     Date: 2022-10-26

Issue 2237 sought to disallow simple-template-ids as constructor names, by referring to the injected-class-name. However, 11.1 [class.pre] paragraph 2 specifies:

The class-name is also bound in the scope of the class (template) itself; this is known as the injected-class-name.

The grammar non-terminal class-name includes the option of a simple-template-id (for declaring a partial specialization).

Proposed resolution (approved by CWG 2023-11-11):

Change in 11.1 [class.pre] paragraph 2 as follows:

The component name of the class-name is also bound in the scope of the class (template) itself; this is known as the injected-class-name. ...



2546. Defaulted secondary comparison operators defined as deleted

Section: 11.10.4  [class.compare.secondary]     Status: tentatively ready     Submitter: Jim X     Date: 2022-03-07

(See also editorial issues 5335 and 5336.)

Consider the example in 11.10.4 [class.compare.secondary] paragraph 3:

  struct HasNoLessThan { };
  struct C {
    friend HasNoLessThan operator<=>(const C&, const C&);
    bool operator<(const C&) const = default;  // OK, function is deleted
  };

While the comment may reflect the intent, it does not follow from the wording. 11.10.4 [class.compare.secondary] paragraph 2 specifies:

The operator function with parameters x and y is defined as deleted if

Otherwise, the operator function yields x @ y. The defaulted operator function is not considered as a candidate in the overload resolution for the @ operator.

Overload resolution applied to x < y results in a usable candidate operator<=> (12.2.1 [over.match.general]) and that candidate is a rewritten candidate (12.2.2.3 [over.match.oper] bullet 3.4), thus operator< in the above example is not deleted. However, its definition is ill-formed, because the rewrite (x <=> y) < 0 is ill-formed (12.2.2.3 [over.match.oper] paragraph 8).

There is implementation divergence.

Subclause 11.10.3 [class.spaceship] paragraph 1 seems to prefer an ill-formed program for similar synthesized situations:

[Note 1: A synthesized three-way comparison is ill-formed if overload resolution finds usable candidates that do not otherwise meet the requirements implied by the defined expression. —end note]

Proposed resolution (approved by CWG 2023-11-07):

Change in 11.10.4 [class.compare.secondary] paragraph 2 as follows:
The operator function with parameters x and y is defined as deleted if

In any overload resolution, the defaulted operator function is not considered as a candidate for the @ operator. Otherwise, the operator function yields x @ y. The defaulted operator function is not considered as a candidate in the overload resolution for the @ operator.




2803. Overload resolution for reference binding of similar types

Section: 12.2.4.2.5  [over.ics.ref]     Status: tentatively ready     Submitter: Brian Bi     Date: 2023-06-14

Consider:

  int foo(int*& r);       // #1
  int foo(const int* const& r); // #2

  int *p;
  int x = foo(p);

Both #1 and #2 perform direct reference binding; no qualification conversions are involved. Despite the lack of a rule, implementations prefer #1 over #2.

Proposed resolution (approved by CWG 2023-11-10):

  1. Change in 12.2.4.2.5 [over.ics.ref] paragraph 1 as follows:

    When a parameter of reference type "reference to cv T" binds directly (9.4.4 [dcl.init.ref]) to an argument expression, the implicit conversion sequence is the identity conversion, unless:
    • If the argument expression has a type that is a derived class of the parameter type, in which case the implicit conversion sequence is a derived-to-base conversion (12.2.4.2 [over.best.ics]).
    • Otherwise, if T is a function type, or if the type of the argument is possibly cv-qualified T, or if T is an array type of unknown bound with element type U and the argument has an array type of known bound whose element type is possibly cv-qualified U, the implicit conversion sequence is the identity conversion. [ Note: When T is a function type, the type of the argument may differ only by the presence of noexcept. -- end note]
    • Otherwise, the implicit conversion sequence is a qualification conversion.

    [Example 1: ... —end example]

    If the parameter binds directly to the result of applying a conversion function to the argument expression, the implicit conversion sequence is a user-defined conversion sequence (12.2.4.2.3 [over.ics.user]) whose second standard conversion sequence is either an identity conversion or, if the conversion function returns an entity of a type that is a derived class of the parameter type, a derived-to-base conversion determined by the above rules.
  2. Change in 12.2.4.3 [over.ics.rank] bullet 3.2.5 as follows:

    • S1 and S2 differ only in their qualification conversion (7.3.6 [conv.qual]) and yield similar types T1 and T2, respectively (where a standard conversion sequence that is a reference binding is considered to yield the cv-unqualified referenced type), where T1 can be converted to T2 by a qualification conversion and T2 are not the same type, and const T2 is reference-compatible with T1 (9.4.4 [dcl.init.ref]). [Example 5:
        int f(const volatile int *);
        int f(const int *);
        int i;
        int j = f(&i);  // calls f(const int*)
        int g(const int*);
        int g(const volatile int* const&);
        int* p;
        int k = g(p);          // calls g(const int*)
      
      -- end example] or, if not that,
  3. Change in 12.2.4.3 [over.ics.rank] bullet 3.2.6 as follows:

    • S1 and S2 include reference bindings bind "reference to T1" and "reference to T2", respectively (9.4.4 [dcl.init.ref]), and the types to which the references refer are the same type except for top-level cv-qualifiers, and the type to which the reference initialized by S2 refers is more cv-qualified than the type to which the reference initialized by S1 refers where T1 and T2 are not the same type, and T2 is reference-compatible with T1. [Example 6: ...
         int h1(int (&)[]);
         int h1(int (&)[1]);
         int h2(void (&)());
         int h2(void (&)() noexcept);
         void g2() {
           int a[1];
           h1(a);            // calls h1(int (&)[1])
           extern void f2() noexcept;
           h2(f2);            // calls h2(void (&)() noexcept)
         }
      
      -- end example ]



2707. Deduction guides cannot have a trailing requires-clause

Section: 13.7.2.3  [temp.deduct.guide]     Status: tentatively ready     Submitter: Richard Smith     Date: 2020-02-26

The grammar for deduction-guide does not, but should, allow a trailing requires-clause:

deduction-guide:
   explicit-specifieropt template-name ( parameter-declaration-clause ) -> simple-template-id ;

Proposed resolution (approved by CWG 2023-11-11):

Change the grammar in 13.7.2.3 [temp.deduct.guide] paragraph 1 as follows:

deduction-guide:
   explicit-specifieropt template-name ( parameter-declaration-clause ) requires-clauseopt -> simple-template-id ;



2775. Unclear argument type for copy of exception object

Section: 14.2  [except.throw]     Status: tentatively ready     Submitter: Jiang An     Date: 2023-05-31

Subclause 14.2 [except.throw] paragraph 5 specifies:

When the thrown object is a class object, the constructor selected for the copy-initialization as well as the constructor selected for a copy-initialization considering the thrown object as an lvalue shall be non-deleted and accessible, even if the copy/move operation is elided (11.9.6 [class.copy.elision]). The destructor is potentially invoked (11.4.7 [class.dtor]).

This provision is for capturing a copy constructor for implementations not using reference-counted std::exception_ptrs, but that ought to be described separately from the "thrown object", which can be interpreted as the operand of the throw-expression.

Proposed resolution (approved by CWG 2023-09-15) [SUPERSEDED]:

Change in 14.2 [except.throw] paragraph 5 as follows:

When the thrown object is a class object, the constructor selected for the copy-initialization as well as the constructor selected for a copy-initialization considering the thrown object as an lvalue shall be non-deleted and accessible, even if the copy/move operation is elided (11.9.6 [class.copy.elision]). Let T denote the type of the exception object. Copy-initialization of an object of type T from an lvalue of type const T in a context unrelated to any class shall be well-formed. If T is a class type, The the destructor of T is potentially invoked (11.4.7 [class.dtor]).

CWG 2023-11-09

The drafting should also consider odr-use of the constructor potentially invoked for the copy-initialization.

Proposed resolution (approved by CWG 2023-11-10):

  1. Change in 6.3 [basic.def.odr] paragraph 9 as follows:

    An assignment operator function in a class is odr-used by an implicitly-defined copy assignment or move assignment function for another class as specified in 11.4.6 [class.copy.assign]. A constructor for a class is odr-used as specified in 9.4 [dcl.init] and when selected for the potential copy-initialization as specified in 14.2 [except.throw]. A destructor for a class is odr-used if it is potentially invoked (11.4.7 [class.dtor]).
  2. Change in 14.2 [except.throw] paragraph 5 as follows:

    When the thrown object is a class object, the constructor selected for the copy-initialization as well as the constructor selected for a copy-initialization considering the thrown object as an lvalue shall be non-deleted and accessible, even if the copy/move operation is elided (11.9.6 [class.copy.elision]). Let T denote the type of the exception object. Copy-initialization of an object of type T from an lvalue of type const T in a context unrelated to T shall be well-formed. If T is a class type, The the destructor of T is potentially invoked (11.4.7 [class.dtor]).





Issues with "Review" Status


2632. 'user-declared' is not defined

Section: Clause 3  [intro.defs]     Status: review     Submitter: Anoop Rana     Date: 2022-09-07

The term "user-declared" is used 30 times throughout the standard, but it is not defined.

Proposed resolution:

Add a new entry after 3.66 [defns.unspecified] as follows:

user-declared [defns.user.declared]

not implicitly declared




2700. #error disallows existing implementation practice

Section: 4.1.1  [intro.compliance.general]     Status: review     Submitter: Richard Smith     Date: 2023-02-13     Liaison: WG14

The resolution for issue 2518 disallows existing implementation practice, as detailed below:

Suggested resolution [SUPERSEDED]:

  1. Change in 4.1.1 [intro.compliance.general] paragraph 2 as follows:

    Furthermore, a conforming implementation
    • shall not accept a preprocessing translation unit containing a #error preprocessing directive (15.8 [cpp.error]), and
    • shall issue at least one diagnostic message for each #warning or #error preprocessing directive not following a #error preprocessing directive in a preprocessing translation unit, and
    • shall not accept a translation unit with a static_assert-declaration that fails (9.1 [dcl.pre]).
  2. Change in 5.1 [lex.separate] paragraph 1 as follows:

    The text of the program is kept in units called source files in this document. A source file together with all the headers (16.4.2.3 [headers]) and source files included (15.3 [cpp.include]) via the preprocessing directive #include, less any source lines skipped by any of the conditional inclusion (15.2 [cpp.cond]) preprocessing directives or by the implementation-defined behavior of any conditionally-supported-directives (15.1 [cpp.pre]), is called a preprocessing translation unit.

CWG 2023-03-03

Permit that #warning can be ignored if another diagnostic is produced.

Proposed resolution:

  1. Change in 4.1.1 [intro.compliance.general] bullet 2.3 as follows:

    • ...
    • Otherwise, if a program contains
      • a violation of any diagnosable rule or,
      • a preprocessing translation unit with a #warning preprocessing directive (15.8 [cpp.error]), or
      • an occurrence of a construct described in this document as “conditionally-supported” when the implementation does not support that construct,
      a conforming implementation shall issue at least one diagnostic message.
  2. Change in 4.1.1 [intro.compliance.general] paragraph 2 as follows:

    Furthermore, a conforming implementation shall not accept
    • a preprocessing translation unit containing a #error preprocessing directive (15.8 [cpp.error]), or
    • shall issue at least one diagnostic message for each #warning or #error preprocessing directive not following a #error preprocessing directive in a preprocessing translation unit, and
    • shall not accept a translation unit with a static_assert-declaration that fails (9.1 [dcl.pre]).
  3. Change in 5.1 [lex.separate] paragraph 1 as follows:

    The text of the program is kept in units called source files in this document. A source file together with all the headers (16.4.2.3 [headers]) and source files included (15.3 [cpp.include]) via the preprocessing directive #include, less any source lines skipped by any of the conditional inclusion (15.2 [cpp.cond]) preprocessing directives, as modified by the implementation-defined behavior of any conditionally-supported-directives (15.1 [cpp.pre]) and pragmas (15.9 [cpp.pragma]), if any, is called a preprocessing translation unit.
  4. Change in 15.8 [cpp.error] as follows:

    A preprocessing directive of either of the following forms the form
    # error pp-tokensopt new-line
    
    renders the program ill-formed. A preprocessing directive of the form
    # warning pp-tokensopt new-line
    
    causes requires the implementation to produce a at least one diagnostic message for the preprocessing translation unit (4.1.1 [intro.compliance.general]) that.

    Recommended practice: Any diagnostic message caused by either of these directives should include the specified sequence of preprocessing tokens; the #error directive renders the program ill-formed.




2726. Alternative tokens appearing as attribute-tokens

Section: 5.5  [lex.digraph]     Status: review     Submitter: Jim X     Date: 2023-03-16     Liaison: EWG

Subclause 5.5 [lex.digraph] paragraph 2 specifies:

In all respects of the language, each alternative token behaves the same, respectively, as its primary token, except for its spelling. [ Footnote: ... ]

However, 9.12.1 [dcl.attr.grammar] paragraph 4 specifies:

... If a keyword (5.11 [lex.key]) or an alternative token (5.5 [lex.digraph]) that satisfies the syntactic requirements of an identifier (5.10 [lex.name]) is contained in an attribute-token, it is considered an identifier. ...

It seems an alternative token (say, or) is treated the same as the operator ||, yet only the alternative token is considered an identifier, not the operator, when appearing in an attribute-token. That seems contradictory.

Proposed resolution (approved by CWG 2023-05-12):

  1. Change in 5.2 [lex.phases] paragraph 2 as follows:

    Whitespace characters separating tokens are no longer significant. Each preprocessing token is converted into a token (5.6 [lex.token]), replacing each alternative token by its corresponding primary token (5.5 [lex.digraph]). The resulting tokens constitute a translation unit and are syntactically and semantically analyzed and translated.
  2. Change in 9.12.1 [dcl.attr.grammar] paragraph 4 as follows:

    ... If a keyword (5.11 [lex.key]) or an alternative token (5.5 [lex.digraph]) that satisfies the syntactic requirements of an identifier (5.10 [lex.name]) is contained in an attribute-token, it is considered an identifier. ...

This resolution also addresses issue 1897.

Additional notes (May, 2023)

During additional discussion on the EWG reflector, Alisdair Meredith expressed that he intends to propose that some alternative tokens be treated as full keywords in phase 7, to prevent and from being used as an rvalue reference and compl from being used for naming destructors. That would reverse the above direction.

Furthermore, an idea was floated to treat all alternative tokens as full keywords in phase 7 and as identifiers in phase 4, amending the grammar productions for expressions as necessary. This removes the special treatment of alternative tokens entirely, however the treatment of examples such as #define and blah would change from ill-formed to well-formed. Some opposition was voiced against changing the phase 4 treatment of alternative tokens.

CWG 2023-06-16

Forwarded to EWG with paper issue #1581.




1924. Definition of “literal” and kinds of literals

Section: 5.13  [lex.literal]     Status: review     Submitter: Saeed Amrollah Boyouki     Date: 2014-05-12     Liaison: editor

The term “literal” is used without definition except the implicit connection with the syntactic nonterminal literal. The relationships of English terms to syntactic nonterminals (such as “integer literal” and integer-literal) should be examined throughout 5.13 [lex.literal] and its subsections.

Notes from the November, 2016 meeting:

This issue will be handled editorially. It is being placed in "review" status until that point.




1897. ODR vs alternative tokens

Section: 6.3  [basic.def.odr]     Status: review     Submitter: Hubert Tong     Date: 2014-03-21

According to 5.5 [lex.digraph] paragraph 2,

In all respects of the language, each alternative token behaves the same, respectively, as its primary token, except for its spelling.

However, the primary and alternative tokens are different tokens, which runs afoul of the ODR requirement in 6.3 [basic.def.odr] paragraph 6 that the definitions consist of the “same sequence of tokens.” This wording should be amended to allow for use of primary and alternative tokens.

CWG 2023-05-12

Addressed by issue 2726.




2551. "Refers to allocated storage" has no meaning

Section: 6.7.3  [basic.life]     Status: review     Submitter: Andrey Erokhin     Date: 2020-09-07

6.7.3 [basic.life] paragraph 6 specifies:

Before the lifetime of an object has started but after the storage which the object will occupy has been allocated or, after the lifetime of an object has ended and before the storage which the object occupied is reused or released, any pointer that represents the address of the storage location where the object will be or was located may be used but only in limited ways. For an object under construction or destruction, see 11.9.5 [class.cdtor]. Otherwise, such a pointer refers to allocated storage (6.7.5.5.2 [basic.stc.dynamic.allocation]), and using the pointer as if the pointer were of type void* is well-defined.

Similarly, 6.7.3 [basic.life] paragraph 7 specifies:

Similarly, before the lifetime of an object has started but after the storage which the object will occupy has been allocated or, after the lifetime of an object has ended and before the storage which the object occupied is reused or released, any glvalue that refers to the original object may be used but only in limited ways. For an object under construction or destruction, see 11.9.5 [class.cdtor]. Otherwise, such a glvalue refers to allocated storage (6.7.5.5.2 [basic.stc.dynamic.allocation]), and using the properties of the glvalue that do not depend on its value is well-defined.

In either case, it is unclear what "refers to allocated storage" means, beyond the properties ascribed to an object in 6.7.2 [intro.object].

See also issue 1853.

Proposed resolution:

  1. Change in 6.7.3 [basic.life] paragraph 6 as follows:

    For an object under construction or destruction, see 11.9.5 [class.cdtor]. Otherwise, such a pointer refers to allocated storage (6.7.5.5.2 [basic.stc.dynamic.allocation]), and using the such a pointer as if the pointer were of type void* is well-defined.
  2. Change in 6.7.3 [basic.life] paragraph 7 as follows:

    For an object under construction or destruction, see 11.9.5 [class.cdtor]. Otherwise, such a glvalue refers to allocated storage (6.7.5.5.2 [basic.stc.dynamic.allocation]), and using the properties of the such a glvalue that do not depend on its value is well-defined.



2677. Replacing union subobjects

Section: 6.7.3  [basic.life]     Status: review     Submitter: Richard Smith     Date: 2022-12-06

The resolution to NB comment US 041 (C++20 CD) does not seem to have fully addressed the original issue, allowing:

  union U { int i, j; };
  U u;
  new (&u) U{.i = 5};
  int k = u.j;  // OK! New U::i transparently replaces existing u.j!

The suggestion is to allow a newly-created complete object to transparently replace any object of the same type in the same storage, except for a potentially-overlapping subobject or a const complete object, and to allow a newly-created subobject to transparently replace only a corresponding subobject of an existing object.

Suggested resolution [SUPERSEDED]:

Change in 6.7.3 [basic.life] paragraph 8 as follows:

... An object o1 is transparently replaceable by an object o2 if:

Additional notes (February, 2023)

The suggested resolution above does not handle the additional example in issue 2676.

Suggested resolution:

  1. Change in 6.7.2 [intro.object] paragraph 2 as follows:

    Objects can contain other objects, called subobjects. A subobject can be a member subobject (11.4 [class.mem]), a base class subobject (11.7 [class.derived]), or an array element. An object that is not a subobject of any other object is called a complete object. If an object is created in storage associated with a member subobject or array element subobject e (which may or may not be within its lifetime), the created object is a subobject of e's containing object if:
    • the lifetime of e's containing object has begun and not ended, and
    • the storage for the new object exactly overlays the storage location associated with e, and
    • e is not a potentially-overlapping subobject, and
    • the new object is of the same type as e (ignoring cv-qualification).
    In this case, e and the created object are corresponding direct subobjects.
  2. Change in 6.7.3 [basic.life] paragraph 8 as follows:

    ... An object o1 is transparently replaceable by an object o2 if either
    • o1 and o2 are complete objects for which:
      • o1 is not const,
      • the storage that o2 occupies exactly overlays the storage that o1 occupied, and
      • o1 and o2 are of the same type (ignoring the top-level cv-qualifiers), and or
      • o1 is not a const, complete object, and
      • neither o1 nor o2 is a potentially-overlapping subobject (6.7.2 [intro.object]), and
    • either o1 and o2 are both complete objects, or o1 and o2 are corresponding direct subobjects of objects p1 and p2, respectively, and p1 is transparently replaceable by p2 (6.7.2 [intro.object]) for which:
      • the complete object of o1 is not const or
      • o1 is a mutable member subobject or a subobject thereof.



2533. Storage duration of implicitly created objects

Section: 6.7.5  [basic.stc]     Status: review     Submitter: Andrey Erokhin     Date: 2022-02-17

In subclause 6.7.2 [intro.object] paragraph 10, operations implicitly creating objects are defined:

Some operations are described as implicitly creating objects within a specified region of storage. For each operation that is specified as implicitly creating objects, that operation implicitly creates and starts the lifetime of zero or more objects of implicit-lifetime types (6.8.1 [basic.types.general]) in its specified region of storage if...

However, the standard does not specify the storage duration that such an implicitly-created object has; this new method of object creation is not mentioned in 6.7.5.1 [basic.stc.general] paragraph 2:

Static, thread, and automatic storage durations are associated with objects introduced by declarations (6.2 [basic.def]) and implicitly created by the implementation (6.7.7 [class.temporary]). The dynamic storage duration is associated with objects created by a new-expression (7.6.2.8 [expr.new]).

With the exception of malloc, the storage duration should probably be that of the object providing storage (if any), similar to the provision for subobjects in 6.7.5.6 [basic.stc.inherit]:

The storage duration of subobjects and reference members is that of their complete object (6.7.2 [intro.object]).

The storage duration of an object created by a non-allocating form of an allocation function (17.6.3.4 [new.delete.placement]) should be treated similarly.

Possible resolution:

  1. Change in 6.7.2 [intro.object] paragraph 13 as follows:

    Any implicit or explicit invocation of a function named operator new or operator new[] implicitly creates objects with dynamic storage duration in the returned region of storage and returns a pointer to a suitable created object.
  2. Change in 6.7.5.1 [basic.stc.general] paragraph 2 as follows:

    Static, thread, and automatic storage durations are associated with objects introduced by declarations (6.2 [basic.def]) and implicitly created by the implementation (6.7.7 [class.temporary]). The dynamic storage duration is associated with objects created by a new-expression (7.6.2.8 [expr.new]) in storage returned by an allocation function (6.7.5.5.2 [basic.stc.dynamic.allocation]) other than a non-allocating form (17.6.3.4 [new.delete.placement]) or by C library memory allocation (20.2.12 [c.malloc]).
  3. Change in 6.7.5.5.2 [basic.stc.dynamic.allocation] paragraph 3 as follows:

    For an allocation function other than a reserved placement allocation function other than a non-allocating form (17.6.3.4 [new.delete.placement]), the pointer returned on a successful call shall represent the address of storage that is aligned as follows:
  4. Change in 6.7.5.6 [basic.stc.inherit] paragraph 1 as follows:

    The storage duration of subobjects and reference members is that of their complete object. The storage duration of an object nested within another object x is the storage duration of x (6.7.2 [intro.object]).
  5. Change in 7.6.2.8 [expr.new] paragraph 9 as follows:

    An object created by a new-expression that invokes an allocation function with a non-allocating form (see below) has the storage duration of the object that used to occupy the region of storage where the new object is created. Objects Any other object created by a new-expression have has dynamic storage duration (6.7.5.5 [basic.stc.dynamic]). [Note 5: The lifetime of such an object is not necessarily restricted to the scope in which it is created. —end note]
  6. Change in 20.2.12 [c.malloc] paragraph 4 as follows:

    These functions implicitly create objects (6.7.2 [intro.object]) with dynamic storage duration in the returned region of storage and return a pointer to a suitable created object. In the case of calloc and realloc, the objects are created before the storage is zeroed or copied, respectively.



2689. Are cv-qualified std::nullptr_t fundamental types?

Section: 6.8.2  [basic.fundamental]     Status: review     Submitter: Anoop Rana     Date: 2022-12-08

It is unclear whether cv std::nullptr_t is a fundamental type, given that it is declared in a library header and cv-qualifications are not mentioned in 6.8.2 [basic.fundamental] paragraph 15.

Proposed resolution:

Change in 6.8.2 [basic.fundamental] paragraph 15 as follows:

The types denoted by std::nullptr_t, const std::nullptr_t, volatile std::nullptr_t, and const volatile std::nullptr_t are distinct types. A value of type std::nullptr_t is a null pointer constant (7.3.12 [conv.ptr]). Such values participate in the pointer and the pointer-to-member conversions (7.3.12 [conv.ptr], 7.3.13 [conv.mem]). sizeof(std::nullptr_t) shall be equal to sizeof(void*).

The types described in this subclause are called fundamental types. [Note 11: Even if the implementation defines two or more fundamental types to have the same value representation, they are nevertheless different types. —end note]




2827. Representation of unsigned integral types

Section: 6.8.2  [basic.fundamental]     Status: review     Submitter: David Detweiler     Date: 2021-09-12

(From editorial issue 4893.)

It is unclear whether the representation of unsigned integral types is unspecified or implementation-defined.

Proposed resolution:

Change in 6.8.2 [basic.fundamental] paragraph 17 as follows:

The types described in this subclause are called fundamental types. The representation of a fundamental type is unspecified except as stated in this subclause.



2587. Visible side effects and initial value of an object

Section: 6.9.2.2  [intro.races]     Status: review     Submitter: Andrey Erokhin     Date: 2022-05-10

Subclause 6.9.2.2 [intro.races] paragraph 13 specifies:

A visible side effect A on a scalar object or bit-field M with respect to a value computation B of M satisfies the conditions: The value of a non-atomic scalar object or bit-field M, as determined by evaluation B, shall be the value stored by the visible side effect A.

However, a side effect is defined as 6.9.1 [intro.execution] paragraph 7:

Reading an object designated by a volatile glvalue (7.2.1 [basic.lval]), modifying an object, calling a library I/O function, or calling a function that does any of those operations are all side effects, which are changes in the state of the execution environment.

It seems that initialization of an object is not a side effect, and thus the value of an scalar object can never be the value obtained during initialization.

Proposed resolution:

Change in 6.9.1 [intro.execution] paragraph 7 as follows:

Reading an object designated by a volatile glvalue (7.2.1 [basic.lval]), modifying an object (including initialization), calling a library I/O function, or calling a function that does any of those operations are all side effects, which are changes in the state of the execution environment. ...



2738. "denotes a destructor" is missing specification

Section: 7.5.4.2  [expr.prim.id.unqual]     Status: review     Submitter: Jim X     Date: 2022-05-22

Subclause 7.5.4.2 [expr.prim.id.unqual] paragraph 1 has a note that lacks a corresponding normative specification:

[Note 1: For operator-function-ids, see 12.4 [over.oper]; for conversion-function-ids, see 11.4.8.3 [class.conv.fct]; for literal-operator-ids, see 12.6 [over.literal]; for template-ids, see 13.3 [temp.names]. A type-name or decltype-specifier prefixed by ~ denotes the destructor of the type so named; see 7.5.4.4 [expr.prim.id.dtor]. Within the definition of a non-static member function, an identifier that names a non-static member is transformed to a class member access expression (11.4.3 [class.mfct.non.static]). —end note]

Proposed resolution:

Change in 7.5.4.2 [expr.prim.id.unqual] paragraph 1 as follows:

A type-name or decltype-specifier prefixed by ~ denotes the destructor of the named type; see 7.5.4.4 [expr.prim.id.dtor]. [Note 1: For operator-function-ids, see 12.4 [over.oper]; for conversion-function-ids, see 11.4.8.3 [class.conv.fct]; for literal-operator-ids, see 12.6 [over.literal]; for template-ids, see 13.3 [temp.names]. A type-name or decltype-specifier prefixed by ~ denotes the destructor of the type so named; see 7.5.4.4 [expr.prim.id.dtor]. Within the definition of a non-static member function, an identifier that names a non-static member is transformed to a class member access expression (11.4.3 [class.mfct.non.static]). —end note]



2549. Implicitly moving the operand of a throw-expression in unevaluated contexts

Section: 7.5.4.3  [expr.prim.id.qual]     Status: review     Submitter: Richard Smith     Date: 2022-03-11

Consider:

  void f() {
    X x;
    // Is x an lvalue or an xvalue here?
    void g(int n = (decltype((throw x, 0))()));  // status quo: x is move-eligible here
  }

  void f() {
    X x;
    struct A {
      void g() {
        try {
          struct Y {
            // Is x an lvalue or an xvalue here?
            void h(int n = (decltype((throw x, 0))()));
          };
        } catch (...) { }
      }
    };
  }

11.9.6 [class.copy.elision] paragraph 3 specifies:

An implicitly movable entity is a variable of automatic storage duration that is either a non-volatile object or an rvalue reference to a non-volatile object type. In the following copy-initialization contexts, a move operation is first considered before attempting a copy operation:

Thus, in the first example above, x is treated as an xvalue, but it is treated as an lvalue in the second example. This outcome is surprising.

(P2266R2 (Simpler implicit move) moved this wording, introduced by P1825R0 (Merged wording for P0527R1 and P1155R3), from 11.9.6 [class.copy.elision] to 7.5.4.3 [expr.prim.id.qual].)

Proposed resolution:

Change in 7.5.4.2 [expr.prim.id.unqual] paragraph 4:

An implicitly movable entity is a variable of with automatic storage duration that is either a non-volatile object or an rvalue reference to a non-volatile object type. In the following contexts, an An id-expression is move-eligible: if



2561. Conversion to function pointer for lambda with explicit object parameter

Section: 7.5.5.2  [expr.prim.lambda.closure]     Status: review     Submitter: Barry Revzin     Date: 2022-02-14     Liaison: EWG

P0847R7 (Deducing this) (approved October, 2021) added explicit-object member functions. Consider:

  struct C {
    C(auto) { }
  };

  void foo() {
    auto l = [](this C) { return 1; };
    void (*fp)(C) = l;
    fp(1); // same effect as decltype(l){}() or decltype(l){}(1) ?
  }

Subclause 7.5.5.2 [expr.prim.lambda.closure] paragraph 8 does not address explicit object member functions:

The closure type for a non-generic lambda-expression with no lambda-capture whose constraints (if any) are satisfied has a conversion function to pointer to function with C++ language linkage (9.11 [dcl.link]) having the same parameter and return types as the closure type's function call operator. The conversion is to “pointer to noexcept function” if the function call operator has a non-throwing exception specification. The value returned by this conversion function is the address of a function F that, when invoked, has the same effect as invoking the closure type's function call operator on a default-constructed instance of the closure type. F is a constexpr function if...

Suggested resolution [SUPERSEDED]:

  1. Change in 7.5.5.2 [expr.prim.lambda.closure] paragraph 8 as follows:

    ... The value returned by this conversion function is
    • for a lambda-expression whose parameter-declaration-clause has an explicit object parameter, the address of the function call operator (7.6.2.2 [expr.unary.op];
    • otherwise, the address of a function F that, when invoked, has the same effect as invoking the closure type's function call operator on a default-constructed instance of the closure type.
    F is a constexpr function if... is an immediate function.

    [ Example:

      struct C {
        C(auto) { }
      };
    
      void foo() {
        auto a = [](C) { return 0; };
        int (*fp)(C) = a;   // OK
        fp(1);              // same effect as decltype(a){}(1)
        auto b = [](this C) { return 1; };
        fp = b;             // OK
        fp(1);              // same effect as (&decltype(b)::operator())(1)
      }
    

    -- end example ]

  2. Change in 7.5.5.2 [expr.prim.lambda.closure] paragraph 11 as follows:

    The value returned by any given specialization of this conversion function template is
    • for a lambda-expression whose parameter-declaration-clause has an explicit object parameter, the address of the corresponding function call operator template specialization (7.6.2.2 [expr.unary.op]);
    • otherwise, the address of a function F that, when invoked, has the same effect as invoking the generic lambda's corresponding function call operator template specialization on a default-constructed instance of the closure type.
    F is a constexpr function if...

CWG 2023-06-17

Requesting guidance from EWG with paper issue 1689.

Additional notes (October, 2023)

Additional examples demonstrating implementation divergence between clang and MSVC:

  struct Any { Any(auto) {} };
  auto x = [](this auto self, int x) { return x; };
  auto y = [](this Any self, int x) { return x; };
  auto z = [](this int (*self)(int), int x) { return x; };
  int main() {
    x(1);
    y(1);
    z(1);
    int (*px)(int) = +x; // MSVC
    int (*py1)(int) = +y; // MSVC
    int (*py2)(Any, int) = +y; // Clang
    int (*pz1)(int) = +z; // MSVC
    int (*pz2)(int (*)(int), int) = +z; // Clang
  }

Additional notes (November, 2023)

Additional example:

  auto c2 = [](this auto self) { return sizeof(self); };
  struct Derived2 : decltype(c) { int value; } d2;
  struct Derived3 : decltype(c) { int value[10]; } d3;

For MSVC, d2() == 4 and d3() == 40, but +d2 and +d3 both point to functions returning 1.

EWG 2023-11-07

Move forward with option 1 "punt" from D3031 for C++26. A future paper can explore other solutions.

Proposed resolution (reviewed by CWG 2023-11-09):

  1. Change the example in 7.5.5.1 [expr.prim.lambda.general] paragraph 6 as follows:

      int i = [](int i, auto a) { return i; }(3, 4);  // OK, a generic lambda
      int j = []<class T>(T t, int i) { return i; }(3, 4);  // OK, a generic lambda
      auto x = [](int i, auto a) { return i; };             // OK, a generic lambda
      auto y = [](this auto self, int i) { return i; };      // OK, a generic lambda
      auto z = []<class T>(int i) { return i; };             // OK, a generic lambda
    
    
  2. Change in 7.5.5.2 [expr.prim.lambda.closure] paragraph 9 as follows:

    The closure type for a non-generic lambda-expression with no lambda-capture and no explicit object parameter (9.3.4.6 [dcl.fct]) whose constraints (if any) are satisfied has a conversion function to pointer to function with C++ language linkage (9.11 [dcl.link]) having the same parameter and return types as the closure type's function call operator. ...
  3. Change in 7.5.5.2 [expr.prim.lambda.closure] paragraph 10 as follows:

    For a generic lambda with no lambda-capture and no explicit object parameter (9.3.4.6 [dcl.fct]), the closure type has a conversion function template to pointer to function. ...

CWG 2023-11-09

Keeping in review status in anticipation of a paper proposing reasonable semantics for the function pointer conversions.




2566. Matching deallocation for uncaught exception

Section: 7.6.2.8  [expr.new]     Status: review     Submitter: Jim X     Date: 2022-04-13

Initialization of an object may terminate via an exception, in which case any dynamically-allocated memory is freed, per 7.6.2.8 [expr.new] paragraph 26:

If any part of the object initialization described above [ Footnote: ... ] terminates by throwing an exception and a suitable deallocation function can be found, the deallocation function is called to free the memory in which the object was being constructed, after which the exception continues to propagate in the context of the new-expression. If no unambiguous matching deallocation function can be found, propagating the exception does not cause the object's memory to be freed.

However, implementations do not consistently support this provision in case the exception remains uncaught:

  #include <iostream>
  struct C {
    void* operator new(std::size_t n) {
      std::cout << "malloc\n";
      return malloc(n);
    }
    void operator delete(void* ptr) {
      std::cout << "free\n";
      free(ptr);
    }
    C() {
      throw 0;
    }
  };
  int main() {
    auto ptr = new C;
  }

Both clang and GCC do not free the memory in this example; they do so if the exception is caught in main.

Maybe a similar provision as used for stack unwinding in 14.4 [except.handle] paragraph 9 is desirable:

If no matching handler is found, the function std::terminate is invoked; whether or not the stack is unwound before this invocation of std::terminate is implementation-defined (14.6.2 [except.terminate]).

Suggested resolution:

Integrate freeing dynamically-allocated memory with stack unwinding (14.3 [except.ctor]), since this is what implementations actually do.

Possible resolution:

  1. Change in 7.6.2.8 [expr.new] paragraph 26, 27, and 28 as follows:

    If any part of the object initialization described above [ Footnote: This can include evaluating a new-initializer and/or calling a constructor. ] terminates by throwing an exception and a suitable deallocation function can be found, the deallocation function is called to free the memory in which the object was being constructed, after which the exception continues to propagate in the context of the new-expression. If no unambiguous matching deallocation function can be found, propagating the exception does not cause the object's memory to be freed. [Note 13: This is appropriate when the called allocation function does not allocate memory; otherwise, it is likely to result in a memory leak. —end note]

    For purposes of stack unwinding (14.3 [except.ctor]), the matching deallocation function is determined as follows: If the new-expression does not begin with a unary :: operator and the allocated type is a class type T or an array thereof, a search is performed for the deallocation function's name in the scope of T. Otherwise, or if nothing is found, the deallocation function's name is looked up by searching for it in the global scope.

    A declaration of a placement deallocation function matches the declaration of a placement allocation function if it has the same number of parameters and, after parameter transformations (9.3.4.6 [dcl.fct]), all parameter types except the first are identical. If the lookup finds a single matching deallocation function, that function will be called is the matching deallocation function; otherwise, no deallocation function will be called there is no matching deallocation function. If the lookup finds a usual deallocation function and that function, considered as a placement deallocation function, would have been selected as a match for the allocation function, the program is ill-formed. For a non-placement allocation function, the normal deallocation function lookup is used to find the matching deallocation function (7.6.2.9 [expr.delete]).

  2. Change in 14.3 [except.ctor] paragraph 1 as follows:

    As control passes from the point where an exception is thrown to a handler, objects are destroyed and deallocation functions are invoked by a process, specified in this subclause, called stack unwinding.
  3. Change in 14.3 [except.ctor] paragraph 5 as follows:

    [Note 4: If the object was allocated by a new-expression (7.6.2.8 [expr.new]), If the evaluation of a new-expression other than the invocation of the allocation function is terminated by an exception, the matching deallocation function (6.7.5.5.3 [basic.stc.dynamic.deallocation]), if any, is called (7.6.2.8 [expr.new]) to free the storage occupied by the object. end note]



2828. Ambiguous interpretation of C-style cast

Section: 7.6.3  [expr.cast]     Status: review     Submitter: Jim X     Date: 2022-03-21

(From editorial issue 5355.)

Consider:

   int*** ptr = 0;
   auto t = (int const*const*const*)ptr;

There is more than one way how this can be interpreted as a static_cast followed by a const_cast, namely:

  const_cast<int const * const * const * >(static_cast<int * * const * >(ptr));
  const_cast<int const * const * const * >(static_cast<int * const * const * >(ptr));

Subclause 7.6.3 [expr.cast] paragraph 4 makes such a program ill-formed:

... If a conversion can be interpreted in more than one way as a static_cast followed by a const_cast, the conversion is ill-formed.

Possible resolution:

Change in 7.6.3 [expr.cast] paragraph 4 as follows:

... If a conversion can be interpreted in more than one of the ways listed above, the interpretation that appears first in the list is used, even if a cast resulting from that interpretation is ill-formed. If a conversion can be interpreted in more than one way as a static_cast followed by a const_cast is used and the conversion can be interpreted in more than one way as such, the conversion is ill-formed.



2593. Insufficient base class restriction for pointer-to-member expression

Section: 7.6.4  [expr.mptr.oper]     Status: review     Submitter: Hubert Tong     Date: 2022-06-04

Consider:

  struct A {};
  struct AA : A { int y; };
  struct B : A { int x; };
  struct C : AA, B {};

  constexpr int f(const A &a) {
    int A::*mp = static_cast<int A::*>(&B::x);
    return a.*mp;
  }

  extern char x[f(static_cast<const AA &>(C{{{}, 13}, {{}, 42}}))];
  extern char x[13];

Subclause 7.6.4 [expr.mptr.oper] paragraph 4 specifies:

Abbreviating pm-expression.*cast-expression as E1.*E2, E1 is called the object expression. If the dynamic type of E1 does not contain the member to which E2 refers, the behavior is undefined.

In the example, the dynamic type of a is C, which does contain B::x, and the undefined behavior provision does not trigger. Thus the call to f is required to yield 42; however common implementations produce 13. The behavior for this case ought to be undefined.

Suggested resolution:

Change in 7.6.4 [expr.mptr.oper] paragraph 4 as follows:

Abbreviating pm-expression.*cast-expression as E1.*E2, E1 is called the object expression. If the dynamic type of E1 does not contain the member to which E2 refers, Where the type of E2 is "pointer to member of T", C is the (unique) class of which the member to which E2 refers is a direct member, and B is the object of type T that either is the result of E1 or is the uniquely so-typed base subobject thereof, if B is neither of type C nor a base class subobject of an object of type C, then the behavior is undefined.



2800. Instantiating constexpr variables for potential constant evaluation

Section: 7.7  [expr.const]     Status: review     Submitter: Shafik Yaghmour     Date: 2023-09-22

Consider:

  template <typename T>
  struct A {
    T data;

    static const A a;
  };
  template <typename T>
  inline constexpr A<T> A<T>::a {42};

  static_assert(A<int>::a.data == 42);

This ought to be well-formed, but there is no rule that would cause instantiation of A<int>::a.

Also consider:

  template<typename T> struct A {
    static T x;
  };
  template<typename T> T A<T>::x = (std::cout << "constructed", T());
  template<typename T> void b(decltype(&A<int>::x));

For the second example, it is undesirable to instantiate A<int>.

Possible resolution [SUPERSEDED]:

Change in 7.7 [expr.const] paragraph 3 as follows:

A variable is potentially-constant if it is constexpr or it has reference or non-volatile const-qualified integral or enumeration type or, for a templated variable, if the definition that would be instantiated if the variable were needed for constant evaluation uses the constexpr decl-specifier (13.7.6.2 [temp.spec.partial.match]).

CWG 2023-10-20

The phrasing suggests that const int variables instantiated from a variable template are no longer potentially-constant.

Possible resolution:

Change in 7.7 [expr.const] paragraph 3 as follows:

A variable is potentially-constant if it is constexpr declared with the constexpr decl-specifier or it has reference or non-volatile const-qualified integral or enumeration type. Such a variable may be instantiated from a templated variable, in which case the definition that would be instantiated if the variable were needed for constant evaluation is considered (13.7.6.2 [temp.spec.partial.match]).



2412. SFINAE vs undeduced placeholder type

Section: 9.2.9.6  [dcl.spec.auto]     Status: review     Submitter: Mike Miller     Date: 2019-05-03

The status of the following example is not clear:

  template <typename T> auto foo(T);  // Not defined

  template <typename T> struct FooCallable {
    template<class U>
    static constexpr bool check_foo_callable(...) { return false; }

    template<class U, class = decltype(foo(U{})) >
    static constexpr bool check_foo_callable(int) { return true; }

    static constexpr bool value = check_foo_callable<T>(0);
  };
  static_assert(FooCallable<int>::value == false, "");

The static_assert causes the evaluation of the default template argument decltype(foo<int>(int{})). However, foo is not defined, leaving it with an undeduced placeholder return type. This situation could conceivably be handled in two different ways. According to 9.2.9.6 [dcl.spec.auto] paragraph 9,

If the name of an entity with an undeduced placeholder type appears in an expression, the program is ill-formed.

This would thus appear to be an invalid expression resulting from substitution in the immediate context of the declaration and thus a substitution failure.

The other alternative would be to treat the presence of an undeduced placeholder type for a function template as satisfying the requirements of 13.9.2 [temp.inst] paragraph 4,

Unless a function template specialization has been explicitly instantiated or explicitly specialized, the function template specialization is implicitly instantiated when the specialization is referenced in a context that requires a function definition to exist or if the existence of the definition affects the semantics of the program.

and attempt to instantiate foo<int>. That instantiation fails because the definition is not provided, which would then be an error outside the immediate context of the declaration and thus a hard error instead of substitution failure.

CWG 2022-11-10

There is no implementation divergence on the handling of this example.

Possible resolution:

Change in 9.2.9.6.1 [dcl.spec.auto.general] paragraph 11 as follows:

If a variable or function with an undeduced placeholder type is named by an expression (6.3 [basic.def.odr]), the program is ill-formed. Once a non-discarded return statement has been seen in a function, however, the return type deduced from that statement can be used in the rest of the function, including in other return statements. [ Example: ...
  template <typename T> auto f(T);     // not defined

  template <typename T> struct F {
    template<class U>
    static constexpr bool g(...) { return false; }

    template<class U, class = decltype(f(U{})) >
    static constexpr bool g(int) { return true; }

    static constexpr bool value = g<T>(0);
  };
  static_assert(F<int>::value == false, "");
-- end example ]



453. References may only bind to “valid” objects

Section: 9.3.4.3  [dcl.ref]     Status: review     Submitter: Gennaro Prota     Date: 18 Jan 2004

9.3.4.3 [dcl.ref] paragraph 4 says:

A reference shall be initialized to refer to a valid object or function. [Note: in particular, a null reference cannot exist in a well-defined program, because the only way to create such a reference would be to bind it to the "object" obtained by dereferencing a null pointer, which causes undefined behavior ...]

What is a "valid" object? In particular the expression "valid object" seems to exclude uninitialized objects, but the response to Core Issue 363 clearly says that's not the intent. This is an example (overloading construction on constness of *this) by John Potter, which I think is supposed to be legal C++ though it binds references to objects that are not initialized yet:

 struct Fun {
    int x, y;
    Fun (int x, Fun const&) : x(x), y(42) { }
    Fun (int x, Fun&) : x(x), y(0) { }
  };
  int main () {
    const Fun f1 (13, f1);
    Fun f2 (13, f2);
    cout << f1.y << " " << f2.y << "\n";
  }

Suggested resolution: Changing the final part of 9.3.4.3 [dcl.ref] paragraph 4 to:

A reference shall be initialized to refer to an object or function. From its point of declaration on (see 6.4.2 [basic.scope.pdecl]) its name is an lvalue which refers to that object or function. The reference may be initialized to refer to an uninitialized object but, in that case, it is usable in limited ways (6.7.3 [basic.life], paragraph 6) [Note: On the other hand, a declaration like this:
    int & ref = *(int*)0;
is ill-formed because ref will not refer to any object or function ]

I also think a "No diagnostic is required." would better be added (what about something like int& r = r; ?)

Proposed Resolution (October, 2004) [SUPERSEDED]:

(Note: the following wording depends on the proposed resolution for issue 232.)

Change 9.3.4.3 [dcl.ref] paragraph 4 as follows:

A reference shall be initialized to refer to a valid object or function. If an lvalue to which a reference is directly bound designates neither an existing object or function of an appropriate type (9.4.4 [dcl.init.ref]), nor a region of memory of suitable size and alignment to contain an object of the reference's type (6.7.2 [intro.object], 6.7.3 [basic.life], 6.8 [basic.types]), the behavior is undefined. [Note: in particular, a null reference cannot exist in a well-defined program, because the only way to create such a reference would be to bind it to the “object” empty lvalue obtained by dereferencing a null pointer, which causes undefined behavior. As does not designate an object or function. Also, as described in 11.4.10 [class.bit], a reference cannot be bound directly to a bit-field. ]

The name of a reference shall not be used in its own initializer. Any other use of a reference before it is initialized results in undefined behavior. [Example:

  int& f(int&);
  int& g();

  extern int& ir3;
  int* ip = 0;

  int& ir1 = *ip;     // undefined behavior: null pointer
  int& ir2 = f(ir3);  // undefined behavior: ir3 not yet initialized
  int& ir3 = g();
  int& ir4 = f(ir4);  // ill-formed: ir4 used in its own initializer
end example]

Rationale: The proposed wording goes beyond the specific concerns of the issue. It was noted that, while the current wording makes cases like int& r = r; ill-formed (because r in the initializer does not "refer to a valid object"), an inappropriate initialization can only be detected, if at all, at runtime and thus "undefined behavior" is a more appropriate treatment. Nevertheless, it was deemed desirable to continue to require a diagnostic for obvious compile-time cases.

It was also noted that the current Standard does not say anything about using a reference before it is initialized. It seemed reasonable to address both of these concerns in the same wording proposed to resolve this issue.

Notes from the April, 2005 meeting:

The CWG decided that whether to require an implementation to diagnose initialization of a reference to itself should be handled as a separate issue (504) and also suggested referring to “storage” instead of “memory” (because 6.7.2 [intro.object] defines an object as a “region of storage”).

Proposed Resolution (April, 2005) [SUPERSEDED]:

(Note: the following wording depends on the proposed resolution for issue 232.)

Change 9.3.4.3 [dcl.ref] paragraph 4 as follows:

A reference shall be initialized to refer to a valid object or function. If an lvalue to which a reference is directly bound designates neither an existing object or function of an appropriate type (9.4.4 [dcl.init.ref]), nor a region of storage of suitable size and alignment to contain an object of the reference's type (6.7.2 [intro.object], 6.7.3 [basic.life], 6.8 [basic.types]), the behavior is undefined. [Note: in particular, a null reference cannot exist in a well-defined program, because the only way to create such a reference would be to bind it to the “object” empty lvalue obtained by dereferencing a null pointer, which causes undefined behavior. As does not designate an object or function. Also, as described in 11.4.10 [class.bit], a reference cannot be bound directly to a bit-field. ]

Any use of a reference before it is initialized results in undefined behavior. [Example:

  int& f(int&);
  int& g();

  extern int& ir3;
  int* ip = 0;

  int& ir1 = *ip;     // undefined behavior: null pointer
  int& ir2 = f(ir3);  // undefined behavior: ir3 not yet initialized
  int& ir3 = g();
  int& ir4 = f(ir4);  // undefined behavior: ir4 used in its own initializer
end example]

Note (February, 2006):

The word “use” in the last paragraph of the proposed resolution was intended to refer to the description in 6.3 [basic.def.odr] paragraph 2. However, that section does not define what it means for a reference to be “used,” dealing only with objects and functions. Additional drafting is required to extend 6.3 [basic.def.odr] paragraph 2 to apply to references.

Additional note (May, 2008):

The proposed resolution for issue 570 adds wording to define “use” for references.

Note, January, 2012:

The resolution should also probably deal with the fact that the “one-past-the-end” address of an array does not designate a valid object (even if such a pointer might “point to” an object of the correct type, per 6.8.4 [basic.compound]) and thus is not suitable for the lvalue-to-rvalue conversion.

CWG 2023-11-06

We need a (possibly out-of-lifetime) object, not just a region of storage here. Empty lvalues do not exist. Otherwise, the direction is confirmed.

Proposed resolution (approved by CWG 2023-11-10):

  1. Change in 7.2.1 [basic.lval] paragraph 11 as follows:

    An object of dynamic type Tobj is type-accessible through a glvalue of type Tref if Tref is similar (7.3.6 [conv.qual]) to:

    • Tobj,
    • a type that is the signed or unsigned type corresponding to Tobj, or
    • a char, unsigned char, or std:byte type.

    If a program attempts to access (3.1 [defns.access]) the stored value of an object through a glvalue whose type is not similar (7.3.6 [conv.qual]) to one of the following types through which it is not type-accessible, the behavior is undefined:.[ Footnote: ... ]
    • the dynamic type of the object,
    • a type that is the signed or unsigned type corresponding to the dynamic type of the object, or
    • a char, unsigned char, or std::byte type.
    If a program invokes a defaulted copy/move constructor or copy/move assignment operator for a union of type U with a glvalue argument that does not denote an object of type cv U within its lifetime, the behavior is undefined.
  2. Change in 7.6.1.3 [expr.call] paragraph 5 as follows:

    A type Tcall is call-compatible with a function type Tfunc if Tcall is the same type as Tfunc or if the type "pointer to Tfunc" can be converted to type "pointer to Tcall" via a function pointer conversion (7.3.14 [conv.fctptr]). Calling a function through an expression whose function type E is different from the function is not call-compatible with the type F of the called function's definition results in undefined behavior unless the type “pointer to F” can be converted to the type “pointer to E” via a function pointer conversion (7.3.14 [conv.fctptr]). [Note 4: The exception applies This requirement allows the case when the expression has the type of a potentially-throwing function, but the called function has a non-throwing exception specification, and the function types are otherwise the same. —end note]
  3. Change and split in 9.3.4.3 [dcl.ref] paragraph 5 as follows:

    There shall be no references to references, no arrays of references, and no pointers to references. The declaration of a reference shall contain an initializer (9.4.4 [dcl.init.ref]) except when the declaration contains an explicit extern specifier (9.2.2 [dcl.stc]), is a class member (11.4 [class.mem]) declaration within a class definition, or is the declaration of a parameter or a return type (9.3.4.6 [dcl.fct]); see 6.2 [basic.def]. A reference shall be initialized to refer to a valid object or function.

    Attempting to bind a reference to a function where the initializer is a glvalue whose type is not call-compatible (7.6.1.3 [expr.call]) with the type of the function's definition results in undefined behavior. Attempting to bind a reference to an object where the initializer is a glvalue through which the object is not type-accessible (7.2.1 [basic.lval]) results in undefined behavior. [Note 2: In particular, a null reference cannot exist in a well-defined program, because the only way to create such a reference would be to bind it to the “object” obtained by indirection through a null pointer, which causes undefined behavior. The object designated by such a glvalue can be outside its lifetime (6.7.3 [basic.life]). Because a null pointer value or a pointer past the end of an object does not point to an object, a reference in a well-defined program cannot refer to such things; see 7.6.2.2 [expr.unary.op]. As described in 11.4.10 [class.bit], a reference cannot be bound directly to a bit-field. —end note] An odr-use (6.3 [basic.def.odr]) of a reference that does not happen after (6.9.2.2 [intro.races]) its initialization results in undefined behavior. [ Example:

    int &f(int&);
    int &g();
    extern int &ir3;
    int *ip = 0;
    int &ir1 = *ip;    // undefined behavior: null pointer
    int &ir2 = f(ir3); // undefined behavior: ir3 not yet initialized
    int &ir3 = g();
    int &ir4 = f(ir4); // undefined behavior: ir4 used in its own initializer
    
    -- end example ]

Additional notes (November, 2023):

An odr-use is a property of the program, not an evaluation that participates in the "happens before" relation.

Possible resolution:

  1. Change in 7.2.1 [basic.lval] paragraph 11 as follows:

    An object of dynamic type Tobj is type-accessible through a glvalue of type Tref if Tref is similar (7.3.6 [conv.qual]) to:

    • Tobj,
    • a type that is the signed or unsigned type corresponding to Tobj, or
    • a char, unsigned char, or std:byte type.

    If a program attempts to access (3.1 [defns.access]) the stored value of an object through a glvalue whose type is not similar (7.3.6 [conv.qual]) to one of the following types through which it is not type-accessible, the behavior is undefined:.[ Footnote: ... ]
    • the dynamic type of the object,
    • a type that is the signed or unsigned type corresponding to the dynamic type of the object, or
    • a char, unsigned char, or std::byte type.
    If a program invokes a defaulted copy/move constructor or copy/move assignment operator for a union of type U with a glvalue argument that does not denote an object of type cv U within its lifetime, the behavior is undefined.
  2. Change in 7.6.1.3 [expr.call] paragraph 5 as follows:

    A type Tcall is call-compatible with a function type Tfunc if Tcall is the same type as Tfunc or if the type "pointer to Tfunc" can be converted to type "pointer to Tcall" via a function pointer conversion (7.3.14 [conv.fctptr]). Calling a function through an expression whose function type E is different from the function is not call-compatible with the type F of the called function's definition results in undefined behavior unless the type “pointer to F” can be converted to the type “pointer to E” via a function pointer conversion (7.3.14 [conv.fctptr]). [Note 4: The exception applies This requirement allows the case when the expression has the type of a potentially-throwing function, but the called function has a non-throwing exception specification, and the function types are otherwise the same. —end note]
  3. Change and split in 9.3.4.3 [dcl.ref] paragraph 5 as follows:

    There shall be no references to references, no arrays of references, and no pointers to references. The declaration of a reference shall contain an initializer (9.4.4 [dcl.init.ref]) except when the declaration contains an explicit extern specifier (9.2.2 [dcl.stc]), is a class member (11.4 [class.mem]) declaration within a class definition, or is the declaration of a parameter or a return type (9.3.4.6 [dcl.fct]); see 6.2 [basic.def]. A reference shall be initialized to refer to a valid object or function.

    Attempting to bind a reference to a function where the initializer is a glvalue whose type is not call-compatible (7.6.1.3 [expr.call]) with the type of the function's definition results in undefined behavior. Attempting to bind a reference to an object where the initializer is a glvalue through which the object is not type-accessible (7.2.1 [basic.lval]) results in undefined behavior. [Note 2: In particular, a null reference cannot exist in a well-defined program, because the only way to create such a reference would be to bind it to the “object” obtained by indirection through a null pointer, which causes undefined behavior. The object designated by such a glvalue can be outside its lifetime (6.7.3 [basic.life]). Because a null pointer value or a pointer past the end of an object does not point to an object, a reference in a well-defined program cannot refer to such things; see 7.6.2.2 [expr.unary.op]. As described in 11.4.10 [class.bit], a reference cannot be bound directly to a bit-field. —end note] If the evaluation of a reference (7.5.4 [expr.prim.id], 7.6.1.5 [expr.ref]) does not happen after (6.9.2.2 [intro.races]) its initialization, the behavior is undefined. [ Example:

    int &f(int&);
    int &g();
    extern int &ir3;
    int *ip = 0;
    int &ir1 = *ip;    // undefined behavior: null pointer
    int &ir2 = f(ir3); // undefined behavior: ir3 not yet initialized
    int &ir3 = g();
    int &ir4 = f(ir4); // undefined behavior: ir4 used in its own initializer
    
    -- end example ]




2553. Restrictions on explicit object member functions

Section: 9.3.4.6  [dcl.fct]     Status: review     Submitter: Jens Maurer     Date: 2021-12-10

Subclause 9.3.4.6 [dcl.fct] paragraph 6 specifies

A member-declarator with an explicit-object-parameter-declaration shall not include a ref-qualifier or a cv-qualifier-seq and shall not be declared static or virtual.

This does not address the situation when an explicit object member function becomes implicitly virtual by overriding an implicit object member function. That should be prevented.

This also does not address class-specific allocation and deallocation functions, which are implicitly static.

Proposed resolution (approved by CWG 2023-06-15) [SUPERSEDED]:

  1. Change in 9.3.4.6 [dcl.fct] paragraph 6 as follows:

    A member-declarator with an explicit-object-parameter-declaration shall not include a ref-qualifier or a cv-qualifier-seq and shall not be declared static or virtual.
  2. Change in 9.3.4.6 [dcl.fct] paragraph 7 as follows:

    ... An implicit object member function is a non-static member function without an explicit object parameter. [ Note: An explicit object member function cannot be virtual (11.7.3 [class.virtual]). -- end note ]
  3. Add a new paragraph before 11.7.3 [class.virtual] paragraph 7 as follows:

    A virtual function shall not be an explicit object member function (9.3.4.6 [dcl.fct]).

    [ Example:

      struct B {
        virtual void g(); // #1
      };
      struct D : B {
        virtual void f(this D&);  // error: explicit object member function cannot be virtual
        void g(this D&);          // error: overrides #1; explicit object member function cannot be virtual
      };
    

    -- end example]

    The ref-qualifier, or lack thereof, ...

Proposed resolution (approved by CWG 2023-07-14):

  1. Change in 9.3.4.6 [dcl.fct] paragraph 6 as follows:

    A member-declarator with an explicit-object-parameter-declaration shall not include a ref-qualifier or a cv-qualifier-seq and shall not be declared static or virtual.
  2. Change in 9.3.4.6 [dcl.fct] paragraph 7 as follows:

    ... An implicit object member function is a non-static member function without an explicit object parameter. [ Note: An explicit object member function cannot be virtual (11.7.3 [class.virtual]). -- end note ]
  3. Change in 11.4.11 [class.free] paragraph 1 as follows:

    Any allocation function for a class T is a static member (even if not explicitly declared static); it shall not have an explicit object parameter.
  4. Change in 11.4.11 [class.free] paragraph 3 as follows:

    Any deallocation function for a class T is a static member (even if not explicitly declared static); it shall not have an explicit object parameter.
  5. Change in 11.4.11 [class.free] paragraph 4 as follows:

    [ Note: Since member allocation and deallocation functions are static they cannot be virtual. -- end note ]
  6. Add a new paragraph before 11.7.3 [class.virtual] paragraph 7 as follows:

    A virtual function shall not be an explicit object member function (9.3.4.6 [dcl.fct]).

    [ Example:

      struct B {
        virtual void g(); // #1
      };
      struct D : B {
        virtual void f(this D&);  // error: explicit object member function cannot be virtual
        void g(this D&);          // error: overrides #1; explicit object member function cannot be virtual
      };
    

    -- end example]

    The ref-qualifier, or lack thereof, ...

CWG 2023-11-09

Progress of this issue is blocked on issue 2554.




2547. Defaulted comparison operator function for non-classes

Section: 9.5.2  [dcl.fct.def.default]     Status: review     Submitter: Jim X     Date: 2022-03-07

(See editorial issue 5337.)

Subclause 9.5.2 [dcl.fct.def.default] paragraph 1 specifies:

A function definition whose function-body is of the form = default ; is called an explicitly-defaulted definition. A function that is explicitly defaulted shall

There seem to be no further restrictions on which comparison operator functions are allowed to be defaulted. For example,

  enum E { };
  bool operator==(E, E) = default;  // well-formed?

Subclause 11.10.1 [class.compare.default] paragraph 1 applies only to comparison operator functions "for some class":

A defaulted comparison operator function (12.4.3 [over.binary]) for some class C shall be a non-template function that is

Proposed resolution:

  1. Change in 9.5.2 [dcl.fct.def.default] paragraph 1 as follows:
    A function definition whose function-body is of the form = default ; is called an explicitly-defaulted definition. A function that is explicitly defaulted shall
  2. Change in 11.10.1 [class.compare.default] paragraph 1 as follows:
    A defaulted comparison operator function (12.4.3 [over.binary]) for some class C shall be a non-template function that is
    • a non-static const non-volatile member of some class C having one parameter of type const C& and either no ref-qualifier or the ref-qualifier &, or
    • a friend of some class C having either two parameters of type const C& or two parameters of type C.

    Such a comparison operator function is termed a comparison operator function for class C. A comparison operator function for class C that is defaulted on its first declaration ...




2554. Overriding virtual functions, also with explicit object parameters

Section: 11.7.3  [class.virtual]     Status: review     Submitter: Jens Maurer     Date: 2021-12-10

Consider:

  struct B {
    virtual void f();   // #1
  };

  struct D : B {
    void f();           // #2
  };

Subclause 11.7.3 [class.virtual] paragraph 2 says:

If a virtual member function F is declared in a class B, and, in a class D derived (directly or indirectly) from B, a declaration of a member function G corresponds (6.4.1 [basic.scope.scope]) to a declaration of F, ignoring trailing requires-clauses, then G overrides [ Footnote: ... ] F .

Subclause 6.4.1 [basic.scope.scope] paragraph 4 defines "corresponds" as follows:

Two declarations correspond if they (re)introduce the same name, both declare constructors, or both declare destructors, unless

Subclause 6.4.1 [basic.scope.scope] paragraph 3 defines "corresponding object parameters" as follows:

Two non-static member functions have corresponding object parameters if:

In the example, B::f has an object parameter of type B, but D::f has an object parameter of type D. Thus, the two functions do not correspond, and thus D::f does not override B::f. That is an unintended alteration of the status quo ante.

See also issue 2553.

Proposed resolution:

  1. Change in 11.7.3 [class.virtual] paragraph 2 as follows:

    If a virtual member function F is declared in a class B, and, in a class D derived (directly or indirectly) from B, a declaration of a member function G corresponds (6.4.1 [basic.scope.scope]) to a declaration of F as if declared in D (12.2.2.1 [over.match.funcs.general]), ignoring trailing requires-clauses, and, if G is an explicit object member function, ignoring object parameters, and, if G is an implicit object member function, F and G have the same ref-qualifier (or absence thereof), then G overrides [ Footnote: ... ] F .
  2. Remove 11.7.3 [class.virtual] paragraph 7 as follows:

    The ref-qualifier , or lack thereof, of an overriding function shall be the same as that of the overridden function.



2756. Completion of initialization by delegating constructor

Section: 11.9  [class.init]     Status: review     Submitter: Brian Bi     Date: 2023-06-20

Subclause 6.7.3 [basic.life] paragraph 1 specifies:

... The lifetime of an object of type T begins when: except that ...

It is unclear whether initialization is considered complete when the (ultimate) target constructor completes, or when the outermost delegating constructor completes. Subclause 14.3 [except.ctor] paragraph 4 suggests it is the former:

If the compound-statement of the function-body of a delegating constructor for an object exits via an exception, the object's destructor is invoked. ...

Proposed resolution (approved by CWG 2023-07-14):

  1. Split and change 11.9.3 [class.base.init] paragraph 9 as follows:

    [Note 3: An abstract class ... -- end note ] An attempt to initialize more than one non-static data member of a union renders the program ill-formed. [Note 4: After the call to a constructor for class X ... -- end note ] [Example 6: ... -- end example ]

    An attempt to initialize more than one non-static data member of a union renders the program ill-formed.

    An object's initialization is considered complete when a non-delegating constructor for that object returns. [Note: Therefore, an object's lifetime can begin (6.7.3 [basic.life]) before all delegating constructors have completed. -- end note]

  2. Change in 6.7.3 [basic.life] bullet 1.2 as follows:

    ... The lifetime of an object of type T begins when:
    • storage with the proper alignment and size for type T is obtained, and
    • its initialization (if any) is complete (including vacuous initialization) (9.4 [dcl.init], 11.9.3 [class.base.init]),
    except that ...

CWG 2023-10-20

Utterances about "during construction or destruction" in 11.9.5 [class.cdtor] need to be adjusted.

Possible resolution:

  1. Split and change 11.9.3 [class.base.init] paragraph 9 as follows:

    [Note 3: An abstract class ... -- end note ] An attempt to initialize more than one non-static data member of a union renders the program ill-formed. [Note 4: After the call to a constructor for class X ... -- end note ] [Example 6: ... -- end example ]

    An attempt to initialize more than one non-static data member of a union renders the program ill-formed.

    An object's initialization is considered complete when a non-delegating constructor for that object returns. [Note: Therefore, an object's lifetime can begin (6.7.3 [basic.life]) before all delegating constructors have completed. -- end note]

  2. Change in 6.7.3 [basic.life] bullet 1.2 as follows:

    ... The lifetime of an object of type T begins when:
    • storage with the proper alignment and size for type T is obtained, and
    • its initialization (if any) is complete (including vacuous initialization) (9.4 [dcl.init], 11.9.3 [class.base.init]),
    except that ...
  3. Change in 11.9.5 [class.cdtor] paragraph 2 as follows:

    During the construction initialization of an object, if the value of the object or any of its subobjects is accessed through a glvalue that is not obtained, directly or indirectly, from the constructor's this pointer, the value of the object or subobject thus obtained is unspecified.
  4. Change in 11.9.5 [class.cdtor] paragraph 4 as follows:

    Member functions, including virtual functions (11.7.3 [class.virtual]), can be called during construction or destruction (11.9.3 [class.base.init]). When a virtual function is called directly or indirectly from a constructor or from a destructor, including during the construction initialization or destruction of the class's non-static data members, and the object to which the call applies is the object (call it x) under construction or destruction being initialized or destroyed, the function called is the final overrider in the constructor's or destructor's class and not one overriding it in a more-derived class. If the virtual function call uses an explicit class member access (7.6.1.5 [expr.ref]) and the object expression refers to the complete object of x or one of that object's base class subobjects but not x or one of its base class subobjects, the behavior is undefined.
  5. Change in 11.9.5 [class.cdtor] paragraph 5 as follows:

    The typeid operator (7.6.1.8 [expr.typeid]) can be used during construction or destruction (11.9.3 [class.base.init]). When typeid is used in a constructor (including the mem-initializer or default member initializer (11.4 [class.mem]) for a non-static data member) or in a destructor, or used in a function called (directly or indirectly) from a constructor or destructor, if the operand of typeid refers to the object under construction or destruction being initialized or destroyed, typeid yields the std::type_info object representing the constructor or destructor's class. If the operand of typeid refers to the object under construction or destruction being initialized or destroyed and the static type of the operand is neither the constructor or destructor's class nor one of its bases, the behavior is undefined.
  6. Change in 11.9.5 [class.cdtor] paragraph 6 as follows:

    dynamic_casts (7.6.1.7 [expr.dynamic.cast]) can be used during construction or destruction (11.9.3 [class.base.init]). When a dynamic_cast is used in a constructor (including the mem-initializer or default member initializer for a non-static data member) or in a destructor, or used in a function called (directly or indirectly) from a constructor or destructor, if the operand of the dynamic_cast refers to the object under construction or destruction being initialized or destroyed, this object is considered to be a most derived object that has the type of the constructor or destructor's class. If the operand of the dynamic_cast refers to the object under construction or destruction being initialized or destroyed and the static type of the operand is not a pointer to or object of the constructor or destructor's own class or one of its bases, the dynamic_cast results in undefined behavior.



2757. Deleting or deallocating storage of an object during its construction

Section: 11.9.5  [class.cdtor]     Status: review     Submitter: Jiang An     Date: 2023-06-14

Subclause 6.7.3 [basic.life] paragraph 6 specifies:

... For an object under construction or destruction, see 11.9.5 [class.cdtor]. Otherwise, ...

However, the referenced subclause does not discuss deleting the object or deallocating its storage.

See also issue 2258.

Proposed resolution (reviewed by CWG 2023-10-20):

  1. Insert before 11.9.5 [class.cdtor] paragraph 2 as follows:

    During the initialization or destruction of an object, invoking the destructor for the object or releasing or reusing (6.7.3 [basic.life]) the storage which the object occupies results in undefined behavior. [ Note: Creating an object nested within some object o does not reuse the storage for o. -- end note ] [ Example:

      struct A() {
        A() {
          ::operator delete(this);
        }
      };
    
      A *p1 = new A;  // undefined behavior
    
      struct B() {
        B() {
          delete this;
        }
      };
    
      B *p2 = new B;  // undefined behavior
    
      struct S {
        constexpr S() { this->~S(); }
        constexpr S(int) {}
      };
    
      constexpr int f() {
        S s(0);
        s.~S();
        std::construct_at(&s);  // #1
        return 0;
      }
    
      constexpr int x = f();  // error: undefined behavior at #1
    

    -- end example ]

    During the construction of an object, if the value of the object ...

  2. Change in 11.9.5 [class.cdtor] paragraph 4 as follows:

    Member functions, including virtual functions (11.7.3 [class.virtual]), other than the destructor can be called during construction or destruction (11.9.3 [class.base.init]). When a virtual function (11.7.3 [class.virtual]) is called directly or indirectly from a constructor or from a destructor, including during the construction or destruction of the class's non-static data members, and ...



2568. Access checking during synthesis of defaulted comparison operator

Section: 11.10.1  [class.compare.default]     Status: review     Submitter: Nicolai Josuttis     Date: 2022-04-11

Consider:

  struct Base {
  protected:
    bool operator==(const Base& other) const = default;
  };

  struct Child : Base {
    int i;
    bool operator==(const Child& other) const = default;
  };

Per 11.10.1 [class.compare.default] paragraph 6,

Let xi be an lvalue denoting the i-th element in the expanded list of subobjects for an object x (of length n), where xi is formed by a sequence of derived-to-base conversions (12.2.4.2 [over.best.ics]), class member access expressions (7.6.1.5 [expr.ref]), and array subscript expressions (7.6.1.2 [expr.sub]) applied to x.

The derived-to-base conversion for this loses the context of access to the protected Base::operator==, violating 11.8.5 [class.protected] paragraph 1. The example is rejected by implementations, but ought to work.

For this related example, there is implementation divergence:

  struct B {
  protected:
    constexpr operator int() const { return 0; }
  };
  struct D : B {
    constexpr bool operator==(const D&) const = default;
  };
  template<typename T> constexpr auto comparable(T t) -> decltype(t == t) { return t == t; }
  constexpr bool comparable(...) { return false; }
  static_assert(comparable(D{}));

Is D::operator== deleted, because its defaulted definition violates the protected access rules? Is D::operator== not deleted, but synthesis fails on use because of the proctected access rules? Is the synthesis not in the immediate context, making the expression comparable(D{}) ill-formed?

CWG 2023-06-17

There is no implementation divergence; the first example is intended to be well-formed.

Possible resolution:

Change in 11.10.1 [class.compare.default] paragraph 1 as follows:

... Name lookups and access checks in the implicit definition (9.5.2 [dcl.fct.def.default]) of a comparison operator function are performed from a context equivalent to its function-body . A definition of a comparison operator as defaulted that appears in a class shall be the first declaration of that function.



2703. Three-way comparison requiring strong ordering for floating-point types, take 2

Section: 11.10.3  [class.spaceship]     Status: review     Submitter: Richard Smith     Date: 2023-02-13

The resolution accepted for issue 2539 does not actually address the example in the issue, because overload resolution is never performed for expressions involved only built-in types.

Suggested resolution:

Change in 11.10.3 [class.spaceship] paragraph 1 as follows:

The synthesized three-way comparison of type R (17.11.2 [cmp.categories]) of glvalues a and b of the same type is defined as follows:



2572. Address of overloaded function with no target

Section: 12.3  [over.over]     Status: review     Submitter: Jason Merrill     Date: 2022-04-26

Consider:

  template <class T> T f(T);   // #1
  template <class T> T* f(T*); // #2
  auto p = &f<int>;

Accoring to 12.3 [over.over] paragraph 3 and 12.3 [over.over] paragraph 5:

The specialization, if any, generated by template argument deduction (13.10.4 [temp.over], 13.10.3.3 [temp.deduct.funcaddr], 13.10.2 [temp.arg.explicit]) for each function template named is added to the set of selected functions considered.

[...]

Any given function template specialization F1 is eliminated if the set contains a second function template specialization whose function template is more specialized than the function template of F1 according to the partial ordering rules of 13.7.7.3 [temp.func.order]. After such eliminations, if any, there shall remain exactly one selected function.

Major implementations reject the example as ambiguous, yet the wording specifies to unambiguously choose #2.

Suggested resolution [SUPERSEDED]:

Change in 12.3 [over.over] paragraph 5 as follows:

Any given function template specialization F1 is eliminated if the set contains a second function template specialization whose function template is more specialized better than the function template of F1. If there is no target, a function template is better than another if it is more constrained than the other; otherwise a function template is better than another if it is more specialized than the other according to the partial ordering rules of 13.7.7.3 [temp.func.order]. After such eliminations, if any, there shall remain exactly one selected function.

Proposed resolution:

Change in 12.3 [over.over] paragraph 5 as follows:

Any If there is a target, any given function template specialization F1 is eliminated if the set contains a second function template specialization whose function template is more specialized than the function template of F1 according to the partial ordering rules of 13.7.7.3 [temp.func.order]. After such eliminations, if any, there shall remain exactly one selected function.



2617. Default template arguments for template members of non-template classes

Section: 13.2  [temp.param]     Status: review     Submitter: Mike Miller     Date: 2022-08-22

Consider:

struct S {
  template<typename> void f();
};

template<typename = int> void S::f() { }   // ok?

There is implementation divergence in the treatment of this example. The relevant wording appears to be 13.2 [temp.param] paragraph 12:

A default template-argument shall not be specified in the template-parameter-lists of the definition of a member of a class template that appears outside of the member's class.

However, the example above deals with a member of an ordinary class, not a class template, but it is not clear why there should be a difference between a member template of a class template and a member template of a non-template class.

Alternatively, it is not clear why the example above should be treated differently from a non-member function template, e.g.,

template<typename> void f();
template<typename = int> void f() { }

which is explicitly permitted.

Proposed resolution:

Change in 13.2 [temp.param] paragraph 10 as follows:

... A default template-argument may be specified in a template declaration. A default template-argument shall not be specified in the template-parameter-lists of the definition of a member of a class template templated class C that appears outside of the member's class class-specifier of C. A default template-argument shall not be specified in a friend class template declaration. If a friend function template declaration D specifies a default template-argument, that declaration shall be a definition and there shall be no other declaration of the function template which is reachable from D or from which D is reachable.



2450. braced-init-list as a template-argument

Section: 13.3  [temp.names]     Status: review     Submitter: Marek Polacek     Date: 2019-01-07

Since non-type template parameters can now have class types, it would seem to make sense to allow a braced-init-list as a template-argument, but the grammar does not permit it.

See also issues 2049 and 2459.

Possible resolution:

The resolution also addresses issue 2049.

  1. Change in 7.3.1 [conv.general] paragraph 3 as follows:

    An expression or braced-init-list E can be implicitly converted to a type T if and only if the declaration T t = E; is well-formed, for some invented temporary variable t (9.4 [dcl.init]).
  2. Change in 7.7 [expr.const] paragraph 12 as follows:

    A converted constant expression of type T is an expression or braced-init-list, implicitly converted to type T, where the converted expression is a constant expression and the implicit conversion sequence contains only (12.1 [over.pre])
    • user-defined conversions,
    • ...
  3. Change in 13.3 [temp.names] paragraph 1 as follows:

    template-argument:
      constant-expression
      type-id
      id-expression
      braced-init-list
    
  4. Change in 13.4.2 [temp.arg.type] paragraph 4 as follows:

      template<auto n> struct B { /* ... */ };
      B<5> b1;        // OK, template parameter type is int
      B<'a'> b2;      // OK, template parameter type is char
      B<2.5> b3;      // OK, template parameter type is double
      B<void(0)> b4;  // error: template parameter type cannot be void
      template<int i> struct C { /* ... */ };
      C<{ 42 }> c1; // OK
    



2589. Context of access checks during constraint satisfaction checking

Section: 13.5.2.3  [temp.constr.atomic]     Status: review     Submitter: Jason Merrill     Date: 2019-10-02

Consider:

  template<class T> concept ctible = requires { T(); };

  class A {
    template <class T> friend struct B;
    A();
  };

  template <class T> struct B;
  template <ctible T> struct B<T> { T t; };
  B<A> b;  // #1

  template <class T> struct C { };
  template <ctible T> struct C<T> { T t; };
  C<A> c;  // #2

Should the context of instantiation be considered for satisfaction checking? If satisfaction checking were always performed in an unrelated context, neither partial specialization is used, and #1 would be ill-formed (because B is incomplete), but #2 would be well-formed. If the satisfaction checking were performed in the context of the constrained declaration, #1 would be well-formed and #2 would be ill-formed, no diagnostic required, because the validity of A() is different in that context. That rule, however, could also consider the context, in which case #2 would also be well-formed.

The decision affects the amount of caching that an implementation can perform.

Subclause 13.5.2.3 [temp.constr.atomic] paragraph 3 should be clarified one way or another:

To determine if an atomic constraint is satisfied, the parameter mapping and template arguments are first substituted into its expression. If substitution results in an invalid type or expression, the constraint is not satisfied. Otherwise, the lvalue-to-rvalue conversion (7.3.2 [conv.lval]) is performed if necessary, and E shall be a constant expression of type bool. The constraint is satisfied if and only if evaluation of E results in true. If, at different points in the program, the satisfaction result is different for identical atomic constraints and template arguments, the program is ill-formed, no diagnostic required.

Proposed resolution:

Change in 13.5.2.3 [temp.constr.atomic] paragraph 3 as follows:

To determine if an atomic constraint is satisfied, the parameter mapping and template arguments are first substituted into its expression. If substitution results in an invalid type or expression, the constraint is not satisfied; access checking is performed in the context in which the constraint-expression or requires-expression appears. Otherwise, the lvalue-to-rvalue conversion (7.3.2 [conv.lval]) is performed if necessary, and E shall be a constant expression of type bool. ...



1602. Linkage of specialization vs linkage of template arguments

Section: 13.9.2  [temp.inst]     Status: review     Submitter: Richard Smith     Date: 2013-01-09

The Standard does not appear to specify the linkage of a template specialization. 13.9.2 [temp.inst] paragraph 11 does say,

Implicitly instantiated class and function template specializations are placed in the namespace where the template is defined.

which could be read as implying that the specialization has the same linkage as the template itself. Implementation practice seems to be that the weakst linkage of the template and the arguments is used for the specialization.

Additional notes (February, 2023)

Template specializations do not have linkage.




2808. Explicit specialization of defaulted special member function

Section: 13.9.2  [temp.inst]     Status: review     Submitter: Richard Smith     Date: 2023-09-21

Consider:

  template<typename T> struct S {
    S(const S&) = default;
    S& operator=(const S&) = default;
    int n;
  };

  // Are the explicit specializations OK?
  template<> S<int>::S(const S&) noexcept { }
  template<> S<int>& S<int>::operator=(const S& other) noexcept {
    return *this;
  }

If the explicit specialization were allowed, would the answer to std::is_trivially_copyable<S<int>> change? What is decltype(&S::operator=) (the defaulted definition is noexcept, yet no instantiation or implicit definition is triggered)?

Proposed resolution (2023-10-20) [SUPERSEDED]:

Change in 13.9.2 [temp.inst] paragraph 3 and add bullets as follows:

The implicit instantiation of a class template specialization causes The implicit instantiation of a class template specialization does not cause the implicit instantiation of default arguments or noexcept-specifiers of the class member functions.

Additional notes (October, 2023)

It is desirable to require a diagnostic for such attempted explicit specializations.

Furthermore, there are situations where the "potentially-throwing" property of a non-deleted function is queried:

  template<int...>
  struct C {
    // This class has no eligible copy assignment operator at all.
    void operator=(const C&) requires false;
    void operator=(int) noexcept;
    operator int() const;
  };

  void f(C<> &c) {
    c = c;        // Convert to int, then construct from int.
  }

  struct D {
    C<> c;
  };

  bool g(D d) {
    return noexcept(d = d);     // #1. If this is valid, what does it return?
  }

  struct E {
    C<> c;
    E &operator=(const E &o) { c = o.c; }
  };

All major implementations agree that E is valid. However, clang, gcc, and EDG delete the copy assignment operator of D, thus sidestepping the question at #1. (MSVC accepts, but #1 returns true despite the potentially-throwing conversion to int.) Apparently, user-defined conversions for the first argument of C's assignment operator are ignored in implementations other than MSVC. However, the specification is silent on that.

Possible resolution:

  1. Change in 13.9.2 [temp.inst] paragraph 3 and add bullets as follows:

    The implicit instantiation of a class template specialization causes
    • the implicit instantiation of the declarations, but not of the definitions, of the non-deleted user-provided class member functions, member classes, scoped member enumerations, static data members, member templates, and friends; and
    • the implicit instantiation of the definitions of [ Note: The implicit instantiation determines whether a defaulted function is deleted, but a non-deleted defaulted function is implicitly defined only when it is odr-used or needed for constant evaluation. -- end note ]
    The implicit instantiation of a class template specialization does not cause the implicit instantiation of default arguments or noexcept-specifiers of the class member functions.
  2. Change in 13.9.4 [temp.expl.spec] paragraph 7 as follows:

    If a template, a member template or a member of a templated class template is explicitly specialized, a declaration of that specialization shall be reachable from every use of that specialization that would cause an implicit instantiation to take place, in every translation unit in which such a use occurs; no diagnostic is required unless the specialization is for a member of a templated class whose definition is implicitly instantiated as a result of the implicit instantiation of the class (13.9.2 [temp.inst]). ...





Issues with "Drafting" Status


369. Are new/delete identifiers or preprocessing-op-or-punc?

Section: 5.4  [lex.pptoken]     Status: drafting     Submitter: Martin v. Loewis     Date: 30 July 2002

5.4 [lex.pptoken] paragraph 2 specifies that there are 5 categories of tokens in phases 3 to 6. With 5.12 [lex.operators] paragraph 1, it is unclear whether new is an identifier or a preprocessing-op-or-punc; likewise for delete. This is relevant to answer the question whether

#define delete foo

is a well-formed control-line, since that requires an identifier after the define token.

(See also issue 189.)




1655. Line endings in raw string literals

Section: 5.4  [lex.pptoken]     Status: drafting     Submitter: Mike Miller     Date: 2013-04-26

According to 5.4 [lex.pptoken] paragraph 3,

If the input stream has been parsed into preprocessing tokens up to a given character:

However, phase 1 is defined as:

Physical source file characters are mapped, in an implementation-defined manner, to the basic source character set (introducing new-line characters for end-of-line indicators) if necessary. The set of physical source file characters accepted is implementation-defined. Trigraph sequences (_N4140_.2.4 [lex.trigraph]) are replaced by corresponding single-character internal representations. Any source file character not in the basic source character set (5.3 [lex.charset]) is replaced by the universal-character-name that designates that character.

The reversion described in 5.4 [lex.pptoken] paragraph 3 specifically does not mention the replacement of physical end-of-line indicators with new-line characters. Is it intended that, for example, a CRLF in the source of a raw string literal is to be represented as a newline character or as the original characters?




1901. punctuator referenced but not defined

Section: 5.6  [lex.token]     Status: drafting     Submitter: Richard Smith     Date: 2014-03-25

The syntactic nonterminal punctuator appears in the grammar for token in 5.6 [lex.token], but it is nowhere defined. It should be merged with operator and given an appropriate list of tokens as a definition for the merged term.

Proposed resolution (October, 2017):

  1. Change 5.5 [lex.digraph] paragraph 2 as follows

  2. In all respects of the language except in an attribute-token (9.12.1 [dcl.attr.grammar]), each alternative token behaves the same, respectively, as its primary token, except for its spelling.18 The set of alternative tokens...
  3. Change the grammar in 5.6 [lex.token] as follows:



  4. Change 5.6 [lex.token] paragraph 1 as follows:

  5. There are five four kinds of tokens: identifiers, keywords, literals,19 operators, and other separators and symbols. Blanks, horizontal and vertical tabs, newlines, formfeeds, and comments (collectively, “white space”), as described below, are ignored except as they serve to separate tokens. [Note: Some white space is required to separate otherwise adjacent identifiers, keywords, numeric literals, and alternative tokens containing alphabetic characters. —end note] Each preprocessing-token resulting from translation phase 6 is converted into the corresponding token as follows:

    [Note: Within an attribute-token (9.12.1 [dcl.attr.grammar]), a token formed from a preprocessing-token that satisfies the syntactic requirements of an identifier is considered to be an identifier with the spelling of the preprocessing-token. —end note]

  6. Delete the final sentence of 5.12 [lex.operators] paragraph 1.

  7. Each preprocessing-op-or-punc is converted to a single token in translation phase 7 (5.2 [lex.phases]).



189. Definition of operator and punctuator

Section: 5.12  [lex.operators]     Status: drafting     Submitter: Mike Miller     Date: 20 Dec 1999

The nonterminals operator and punctuator in 5.6 [lex.token] are not defined. There is a definition of the nonterminal operator in 12.4 [over.oper] paragraph 1, but it is apparent that the two nonterminals are not the same: the latter includes keywords and multi-token operators and does not include the nonoverloadable operators mentioned in paragraph 3.

There is a definition of preprocessing-op-or-punc in 5.12 [lex.operators] , with the notation that

Each preprocessing-op-or-punc is converted to a single token in translation phase 7 (2.1).
However, this list doesn't distinguish between operators and punctuators, it includes digraphs and keywords (can a given token be both a keyword and an operator at the same time?), etc.

Suggested resolution:


  1. Change 12.4 [over.oper] to use the term overloadable-operator.
  2. Change 5.6 [lex.token] to use the term operator-token instead of operator (since there are operators that are keywords and operators that are composed of more than one token).
  3. Change 5.12 [lex.operators] to define the nonterminals operator-token and punctuator.

Additional note (April, 2005):

The resolution for this problem should also address the fact that sizeof and typeid (and potentially others like decltype that may be added in the future) are described in some places as “operators” but are not listed in 12.4 [over.oper] paragraph 3 among the operators that cannot be overloaded.

(See also issue 369.)




1723. Multicharacter user-defined character literals

Section: 5.13.9  [lex.ext]     Status: drafting     Submitter: Mike Miller     Date: 2013-07-31

According to 5.13.3 [lex.ccon] paragraph 1, a multicharacter literal like 'ab' is conditionally-supported and has type int.

According to 5.13.9 [lex.ext] paragraph 6,

If L is a user-defined-character-literal, let ch be the literal without its ud-suffix. S shall contain a literal operator (12.6 [over.literal]) whose only parameter has the type of ch and the literal L is treated as a call of the form

A user-defined-character-literal like 'ab'_foo would thus require a literal operator

However, that is not one of the signatures permitted by 12.6 [over.literal] paragraph 3.

Should multicharacter user-defined-character-literals be conditionally-supported? If so, 12.6 [over.literal] paragraph 3 should be adjusted accordingly. If not, a note in 5.13.9 [lex.ext] paragraph 6 saying explicitly that they are not supported would be helpful.




1735. Out-of-range literals in user-defined-literals

Section: 5.13.9  [lex.ext]     Status: drafting     Submitter: Mike Miller     Date: 2013-08-12

The description of the numeric literals occurring as part of user-defined-integer-literals and user-defined-floating-literals in 5.13.9 [lex.ext] says nothing about whether they are required to satisfy the same constraints as literals that are not part of a user-defined-literal. In particular, because it is the spelling, not the value, of the literal that is used for raw literal operators and literal operator templates, there is no particular reason that they should be restricted to the maximum values and precisions that apply to ordinary literals (and one could imagine that this would be a good notation for allowing literals of extended-precision types).

Is this relaxation of limits intended to be required, or is it a quality-of-implementation issue? Should something be said, either normatively or non-normatively, about this question?




1529. Nomenclature for variable vs reference non-static data member

Section: 6.1  [basic.pre]     Status: drafting     Submitter: Daniel Krügler     Date: 2012-07-24

According to 6.1 [basic.pre] paragraph 6,

A variable is introduced by the declaration of a reference other than a non-static data member or of an object.

In other words, non-static data members of reference type are not variables. This complicates the wording in a number of places, where the text refers to “variable or data member,” presumably to cover the reference case, but that phrasing could lead to the mistaken impression that all data members are not variables. It would be better if either there were a term for the current phrase “variable or data member” or if there were a less-unwieldy term for “non-static data member of reference type” that could be used in place of “data member” in the current phrasing.




2480. Lookup for enumerators in modules

Section: 6.5.1  [basic.lookup.general]     Status: drafting     Submitter: Richard Smith     Date: 2021-02-12

According to 6.5.1 [basic.lookup.general] paragraphs 2-3,

...A declaration X precedes a program point P in a translation unit L if P follows X, X inhabits a class scope and is reachable from P, or else...

A single search in a scope S for a name N from a program point P finds all declarations that precede P to which any name that is the same as N (6.1 [basic.pre]) is bound in S.

These rules cause problems for finding enumerators when qualified by an exported name of its enumeration type, unlike a member of a class. For example:

  export module A;
  enum class X { x };
  enum Y { y };

  export module B;
  import A;
  export using XB = X;
  export using YB = Y;

  // client code
  import B;
  int main() {
    XB x = XB::x; // should be OK because definition of X is reachable, even
                  // though A is not imported
    YB y = YB::y; // similarly OK
    YB z = ::y;   // error, because y from module A is not visible
  }

It would seem that this problem could be addressed by changing “inhabits a class scope” to “does not inhabit a namespace scope.”




1089. Template parameters in member selections

Section: 6.5.5.1  [basic.lookup.qual.general]     Status: drafting     Submitter: Daveed Vandevoorde     Date: 2010-06-29

In an example like

    template<typename T> void f(T p)->decltype(p.T::x);

The nested-name-specifier T:: looks like it refers to the template parameter. However, if this is instantiated with a type like

    struct T { int x; };
    struct S: T { };

the reference will be ambiguous, since it is looked up in both the context of the expression, finding the template parameter, and in the class, finding the base class injected-class-name, and this could be a deduction failure. As a result, the same declaration with a different parameter name

    template<typename U> void f(U p)->decltype(p.U::x);

is, in fact, not a redeclaration because the two can be distinguished by SFINAE.

It would be better to add a new lookup rule that says that if a name in a template definition resolves to a template parameter, that name is not subject to further lookup at instantiation time.

Additional note (November, 2020):

Paper P1787R6, adopted at the November, 2020 meeting, partially addresses this issue.




2324. Size of base class subobject

Section: 6.7.2  [intro.object]     Status: drafting     Submitter: GB     Date: 2017-02-27

P0488R0 comment GB 9

According to 6.7.2 [intro.object] paragraph 7,

Unless it is a bit-field (11.4.10 [class.bit]), a most derived object shall have a nonzero size and shall occupy one or more bytes of storage. Base class subobjects may have zero size.

Base class objects of zero size is a misleading term, as sizeof such an object is non-zero. Size should not be a property of an object, rather of a type.




2325. std::launder and reuse of character buffers

Section: 6.7.2  [intro.object]     Status: drafting     Submitter: CA     Date: 2017-02-27

P0488R0 comment CA 12

The status of the following code should be explicitly indicated in the Standard to avoid surprise:

  #include <new>
  int bar() {
    alignas(int) unsigned char space[sizeof(int)];
    int *pi = new (static_cast<void *>(space)) int;
    *pi = 42;
    return [=]() mutable {
      return   *std::launder(reinterpret_cast<int *>(space)); }();
   }

In particular, it appears that the call to std::launder has undefined behaviour because the captured copy of space is not established to provide storage for an object of type int (sub 6.7.2 [intro.object] paragraph 1). Furthermore, the code has undefined behaviour also because it attempts to access the stored value of the int object through a glvalue of an array type other than one of the ones allowed by sub 7.2.1 [basic.lval] paragraph 8.




2469. Implicit object creation vs constant expressions

Section: 6.7.2  [intro.object]     Status: drafting     Submitter: Hubert Tong     Date: 2020-12-07

It is not intended that implicit object creation, as described in 6.7.2 [intro.object] paragraph 10, should occur during constant expression evaluation, but there is currently no wording prohibiting it.

Notes from the February, 2021 teleconference:

This issue was occasioned by issue 2464, which is also the subject of LWG issue 3495. CWG reviewed the proposed resolution and agrees with it. The intended approach for this issue is to wait for LWG to resolve that issue, then add a note in the core section pointing out the implications of that requirement for implicit object creation.




1027. Type consistency and reallocation of scalar types

Section: 6.7.3  [basic.life]     Status: drafting     Submitter: Gabriel Dos Reis     Date: 2010-02-03

Is the following well-formed?

    int f() {
        int i = 3;
        new (&i) float(1.2);
        return i;
    }

The wording that is intended to prevent such shenanigans, 6.7.3 [basic.life] paragraphs 7-9, doesn't quite apply here. In particular, paragraph 7 reads,

If, after the lifetime of an object has ended and before the storage which the object occupied is reused or released, a new object is created at the storage location which the original object occupied, a pointer that pointed to the original object, a reference that referred to the original object, or the name of the original object will automatically refer to the new object and, once the lifetime of the new object has started, can be used to manipulate the new object, if:

The problem here is that this wording only applies “after the lifetime of an object has ended and before the storage which the object occupied is reused;” for an object of a scalar type, its lifetime only ends when the storage is reused or released (paragraph 1), so it appears that these restrictions cannot apply to such objects.

(See also issues 1116 and 1338.)

Proposed resolution (August, 2010):

This issue is resolved by the resolution of issue 1116.




1530. Member access in out-of-lifetime objects

Section: 6.7.3  [basic.life]     Status: drafting     Submitter: Howard Hinnant     Date: 2012-07-26

According to 6.7.3 [basic.life] paragraphs 5 and 6, a program has undefined behavior if a pointer or glvalue designating an out-of-lifetime object

is used to access a non-static data member or call a non-static member function of the object

It is not clear what the word “access” means in this context. A reasonable interpretation might be using the pointer or glvalue as the left operand of a class member access expression; alternatively, it might mean to read or write the value of that member, allowing a class member access expression that is used only to form an address or bind a reference.

This needs to be clarified. A relevant consideration is the recent adoption of the resolution of issue 597, which eased the former restriction on simple address manipulations involving out-of-lifetime objects: if base-class offset calculations are now allowed, why not non-static data member offset calculations?

(See also issue 1531 for other uses of the term “access.”)

Additional note (January, 2013):

A related question is the meaning of the phrase “before the constructor begins execution” in 11.9.5 [class.cdtor] paragraph 1 means:

For an object with a non-trivial constructor, referring to any non-static member or base class of the object before the constructor begins execution results in undefined behavior.

For example:

  struct DerivedMember { ... };

  struct Base {
    Base(DerivedMember const&);
  };

  struct Derived : Base {
    DerivedMember x;
    Derived() : Base(x) {}
  };

  Derived a;

Is the reference to Derived::x in the mem-initializer valid?

Additional note (March, 2013):

This clause is phrased in terms of the execution of the constructor. However, it is possible for an aggregate to have a non-trivial default constructor and be initialized without executing a constructor. The wording needs to be updated to allow for non-constructor initialization to avoid appearing to imply undefined behavior for an example like:

  struct X {
    std::string s;
  } x = {};
  std::string t = x.s;  // No constructor called for x: undefined behavior?



1997. Placement new and previous initialization

Section: 6.7.4  [basic.indet]     Status: drafting     Submitter: Jason Merrill     Date: 2014-09-08

Given the following example,

  #include <new>

  int main() {
    unsigned char buf[sizeof(int)] = {};
    int *ip = new (buf) int;
    return *ip; // 0 or undefined?
  }

Should the preceding initializsation of the buffer carry over to the value of *ip? According to 6.7.4 [basic.indet] paragraph 1,

When storage for an object with automatic or dynamic storage duration is obtained, the object has an indeterminate value, and if no initialization is performed for the object, that object retains an indeterminate value until that value is replaced (7.6.19 [expr.ass]).

In this case, no new storage is being obtained for the int object created by the new-expression.




1634. Temporary storage duration

Section: 6.7.5  [basic.stc]     Status: drafting     Submitter: Richard Smith     Date: 2013-03-04

According to 6.7.5 [basic.stc] paragraph 2,

Static, thread, and automatic storage durations are associated with objects introduced by declarations (6.2 [basic.def]) and implicitly created by the implementation (6.7.7 [class.temporary]).

The apparent intent of the reference to 6.7.7 [class.temporary] is that a temporary whose lifetime is extended to be that of a reference with one of those storage durations is considered also to have that storage duration. This interpretation is buttressed by use of the phrase “an object with the same storage duration as the temporary” (twice) in 6.7.7 [class.temporary] paragraph 5.

There are two problems, however: first, the specification of lifetime extension of temporaries (also in 6.7.7 [class.temporary] paragraph 5) does not say anything about storage duration. Also, nothing is said in either of these locations about the storage duration of a temporary whose lifetime is not extended.

The latter point is important because 6.7.3 [basic.life] makes a distinction between the lifetime of an object and the acquisition and release of the storage the object occupies, at least for objects with non-trivial initialization and/or a non-trivial destructor. The assumption is made in 6.7.7 [class.temporary] and elsewhere that the storage in which a temporary is created is no longer available for reuse, as specified in 6.7.3 [basic.life], after the lifetime of the temporary has ended, but this assumption is not explicitly stated. One way to make that assumption explicit would be to define a storage duration for temporaries whose lifetime is not extended.

See also issues 365 and 2256.




1676. auto return type for allocation and deallocation functions

Section: 6.7.5.5.2  [basic.stc.dynamic.allocation]     Status: drafting     Submitter: Richard Smith     Date: 2013-05-04

Do we need explicit language to forbid auto as the return type of allocation and deallocation functions?

(See also issue 1669.)




2073. Allocating memory for exception objects

Section: 6.7.5.5.2  [basic.stc.dynamic.allocation]     Status: drafting     Submitter: Jonathan Wakely     Date: 2015-01-20

According to 6.7.5.5.2 [basic.stc.dynamic.allocation] paragraph 4,

[Note: In particular, a global allocation function is not called to allocate storage for objects with static storage duration (6.7.5.2 [basic.stc.static]), for objects or references with thread storage duration (6.7.5.3 [basic.stc.thread]), for objects of type std::type_info (7.6.1.8 [expr.typeid]), or for an exception object (14.2 [except.throw]). —end note]

The restriction against allocating exception objects on the heap was intended to ensure that heap exhaustion could be reported by throwing an exception, i.e., that obtaining storage for std::bad_alloc could not fail because the heap was full. However, this implicitly relied on the assumption of a single thread and does not scale to large numbers of threads, so the restriction should be lifted and another mechanism found for guaranteeing the ability to throw std::bad_alloc.

Notes from the February, 2016 meeting:

The prohibition of using an allocation function appears only in a note, although there is a normative reference to the rule in 14.2 [except.throw] paragraph 4. CWG was in favor of retaining the prohibition of using a C++ allocation function for the memory of an exception object, with the implicit understanding that use of malloc would be permitted. The resolution for this issue should delete the note and move the prohibition to normative text in the relevant sections.




2042. Exceptions and deallocation functions

Section: 6.7.5.5.3  [basic.stc.dynamic.deallocation]     Status: drafting     Submitter: Richard Smith     Date: 2014-11-13

According to 6.7.5.5.3 [basic.stc.dynamic.deallocation] paragraph 3,

If a deallocation function terminates by throwing an exception, the behavior is undefined.

This seems to be in conflict with the provisions of 14.5 [except.spec]: if a deallocation function throws an exception that is not allowed by its exception-specification, 14.5 [except.spec] paragraph 10 would appear to give the program defined behavior (calling std::unexpected() or std::terminate()). (Note that 14.5 [except.spec] paragraph 18 explicitly allows an explicit exception-specification for a deallocation function.)




1211. Misaligned lvalues

Section: 6.7.6  [basic.align]     Status: drafting     Submitter: David Svoboda     Date: 2010-10-20

6.7.6 [basic.align] speaks of “alignment requirements,” and 6.7.5.5.2 [basic.stc.dynamic.allocation] requires the result of an allocation function to point to “suitably aligned” storage, but there is no explicit statement of what happens when these requirements are violated (presumably undefined behavior).




1701. Array vs sequence in object representation

Section: 6.8  [basic.types]     Status: drafting     Submitter: Lawrence Crowl     Date: 2013-06-14

According to 6.8 [basic.types] paragraph 4,

The object representation of an object of type T is the sequence of N unsigned char objects taken up by the object of type T, where N equals sizeof(T).

However, it is not clear that a “sequence” can be indexed, as an array can and as is required for the implementation of memcpy and similar code.

Additional note, November, 2014:

An additional point of concern has been raised as to whether it is appropriate to refer to the constituent bytes of an object as being “objects” themselves, along with the interaction of this specification with copying or not copying parts of the object representation that do not participate in the value representation of the object (“padding” bytes).




1986. odr-use and delayed initialization

Section: 6.9.3.2  [basic.start.static]     Status: drafting     Submitter: Richard Smith     Date: 2014-08-21

The current wording of 6.9.3.2 [basic.start.static] allows deferral of static and thread_local initialization until a variable or function in the containing translation unit is odr-used. This requires implementations to avoid optimizing away the relevant odr-uses. We should consider relaxing the rule to allow for such optimizations.

Proposed resolution (November, 2014):

For a variable V with thread or static storage duration, let X be the set of all variables with the same storage duration as V that are defined in the same translation unit as V. If the observable behavior of the abstract machine (6.7.2 [intro.object]) depends on the value of V through an evaluation E, and E is not sequenced before the end of the initialization of any variable in X, then the end of the initialization of all variables in X is sequenced before E.

There is also a problem (submitted by David Majnemer) if the odr-use occurs in a constexpr context that does not require the variable to be constructed. For example,

  struct A { A(); };
  thread_local A a;

  constexpr bool f() { return &a != nullptr; }

It doesn't seem possible to construct a before its odr-use in f.

There is implementation divergence in the handling of this example.

Notes from the November, 2014 meeting:

CWG determined that the second part of the issue (involving constexpr) is not a defect because the address of an object with thread storage duration is not a constant expression.

Additional note, May, 2015:

CWG failed to indicate where and how to apply the wording in the proposed resolution. In addition, further review has raised concern that “sequenced before” may be the wrong relation to use for the static storage duration case because it implies “in the same thread.”

Notes from the October, 2015 meeting:

The suggested wording is intended to replace some existing wording in 6.9.3.2 [basic.start.static] paragraph 2. CWG affirmed that the correct relationship is “happens before” and not “sequenced before.”




2148. Thread storage duration and order of initialization

Section: 6.9.3.2  [basic.start.static]     Status: drafting     Submitter: Hubert Tong     Date: 2015-06-22

The terms “ordered” and “unordered” initialization are only defined in 6.9.3.2 [basic.start.static] paragraph 2 for entities with static storage duration. They should presumably apply to entities with thread storage duration as well.




2444. Constant expressions in initialization odr-use

Section: 6.9.3.3  [basic.start.dynamic]     Status: drafting     Submitter: Davis Herring     Date: 2019-11-06

According to 6.9.3.3 [basic.start.dynamic] paragraph 3,

A non-initialization odr-use is an odr-use (6.3 [basic.def.odr]) not caused directly or indirectly by the initialization of a non-local static or thread storage duration variable.

Paragraphs 4-6 uses this term to exclude such odr-uses from consideration in determining the point by which a deferred initialization must be performed. A static_assert or a template argument expression can odr-use a variable, but it cannot be said to define any time during execution.

Suggestion: Add constant expression evaluation to the definition. Rename the term to “initializing odr-use” (based on effect rather than cause). Add a note saying that no such odr-use can occur before main begins.

Notes from the February, 2021 teleconference:

CWG agreed with the direction.




2503. Unclear relationship among name, qualified name, and unqualified name

Section: 7.5.4  [expr.prim.id]     Status: drafting     Submitter: Jens Maurer     Date: 2021-08-04

The phrases “name”, “qualified name” and “unqualified name” are used in various places. It is not clear that all names are either one or the other; there could, in fact, be a third kind of name that is neither.

See also editorial issue 4793.




2473. Parentheses in pseudo-destructor calls

Section: 7.5.4.4  [expr.prim.id.dtor]     Status: drafting     Submitter: Mike Miller     Date: 2020-12-15

According to 7.5.4.4 [expr.prim.id.dtor] paragraph 2,

If the id-expression names a pseudo-destructor, T shall be a scalar type and the id-expression shall appear as the right operand of a class member access (7.6.1.5 [expr.ref]) that forms the postfix-expression of a function call (7.6.1.3 [expr.call]).

This would appear to make the following example ill-formed, because it is the parenthesized expression and not the class member access that is the postfix-expression in the function call:

  typedef int T;
  void f(int* p) {
    (p->~T)();   // Ill-formed?
  }

Presumably this is an oversight.




2086. Reference odr-use vs implicit capture

Section: 7.5.5.3  [expr.prim.lambda.capture]     Status: drafting     Submitter: Hubert Tong     Date: 2015-02-14

Whether a reference is odr-used or not has less to do with the context where it is named and more to do with its initializer. In particular, 7.5.5 [expr.prim.lambda] bullet 12.2 leads to cases where references that can never be odr-used are implicitly captured:

A lambda-expression with an associated capture-default that does not explicitly capture this or a variable with automatic storage duration (this excludes any id-expression that has been found to refer to an init-capture's associated non-static data member), is said to implicitly capture the entity (i.e., this or a variable) if the compound-statement:

For example, ref should not be captured in the following:

  struct A {
    A() = default;
    A(const A &) = delete;
  } globalA;

  constexpr bool bar(int &, const A &a) { return &a == &globalA; }

  int main() {
    A &ref = globalA;
    [=](auto q) { static_assert(bar(q, ref), ""); }(0);
  }



1521. T{expr} with reference types

Section: 7.6.1.4  [expr.type.conv]     Status: drafting     Submitter: Steve Adamczyk     Date: 2012-07-10

According to 7.6.1.4 [expr.type.conv] paragraph 4,

Similarly, a simple-type-specifier or typename-specifier followed by a braced-init-list creates a temporary object of the specified type direct-list-initialized (9.4.5 [dcl.init.list]) with the specified braced-init-list, and its value is that temporary object as a prvalue.

This wording does not handle the case where T is a reference type: it is not possible to create a temporary object of that type, and presumably the result would be an xvalue, not a prvalue.




2283. Missing complete type requirements

Section: 7.6.1.4  [expr.type.conv]     Status: drafting     Submitter: Richard Smith     Date: 2016-06-27

P0135R1 (Wording for guaranteed copy elision through simplified value categories) removes complete type requirements from 7.6.1.3 [expr.call] (under the assumption that subclause 9.4 [dcl.init] has them; apparently it does not) and from 7.6.1.8 [expr.typeid] paragraph 3. These both appear to be bad changes and should presumably be reverted.




2557. Class member access referring to an unrelated class

Section: 7.6.1.5  [expr.ref]     Status: drafting     Submitter: Jens Maurer     Date: 2022-03-25

Consider:

  struct A {
    static int x;
  };

  struct B {
    using type = A;
  };

  int y = B().type::x;

There seems to be no requirement that the member named in a class member access actually is a member of the class of the object expression. Subclause 7.5.4.1 [expr.prim.id.general] paragraph 3 does not cover static members:

An id-expression that denotes a non-static data member or non-static member function of a class can only be used:

Suggested resolution:

  1. Change in 7.6.1.5 [expr.ref] paragraph 4 as follows:

    Otherwise, the object expression shall be of class type. The class type shall be complete unless the class member access appears in the definition of that class.
    [Note: The program is ill-formed if the result differs from that when the class is complete (6.5.2 [class.member.lookup]). —end note]
    [Note: 6.5.5 [basic.lookup.qual] describes how names are looked up after the . and -> operators. —end note] If E2 is a qualified-id, the terminal name of its nested-name-specifier shall denote the type of E1 or a base class thereof.

    [Example:

      struct A {
        static int x;
      };
    
      struct B {
        static int x;
      };
    
      struct D : B {
        using type = A;
      };
    
      int y1 = D().B::x;         // OK, B is a base class of D
      int y2 = D().type::x;      // error: A is not a base class of D
      int y3 = D::type::x;       // OK, evaluates A::x
    

    end example ]

  2. Change in 7.6.1.5 [expr.ref] bullet 6.5 as follows:

  3. Change in 7.5.4.1 [expr.prim.id.general] paragraph 3 as follows:

    An id-expression that denotes a non-static data member or non-static member function of a class can only be used:
    • as part of a class member access (7.6.1.5 [expr.ref]) in which the object expression refers to the member's class [ Footnote: ... ] or a class derived from that class, or
    • to form a pointer to member (7.6.2.2 [expr.unary.op]), or
    • if that id-expression denotes a non-static data member and it appears in an unevaluated operand.



1965. Explicit casts to reference types

Section: 7.6.1.7  [expr.dynamic.cast]     Status: drafting     Submitter: Richard Smith     Date: 2014-07-07

The specification of dynamic_cast in 7.6.1.7 [expr.dynamic.cast] paragraph 2 (and const_cast in 7.6.1.11 [expr.const.cast] is the same) says that the operand of a cast to an lvalue reference type must be an lvalue, so that

  struct A { virtual ~A(); }; A &&make_a();

  A &&a = dynamic_cast<A&&>(make_a());   // ok
  const A &b = dynamic_cast<const A&>(make_a()); // ill-formed

The behavior of static_cast is an odd hybrid:

  struct B : A { }; B &&make_b();
  A &&c = static_cast<A&&>(make_b()); // ok
  const A &d = static_cast<const A&>(make_b()); // ok
  const B &e = static_cast<const B&>(make_a()); // ill-formed

(Binding a const lvalue reference to an rvalue is permitted by 7.6.1.9 [expr.static.cast] paragraph 4 but not by paragraphs 2 and 3.)

There is implementation divergence on the treatment of these examples.

Also, const_cast permits binding an rvalue reference to a class prvalue but not to any other kind of prvalue, which seems like an unnecessary restriction.

Finally, 7.6.1.9 [expr.static.cast] paragraph 3 allows binding an rvalue reference to a class or array prvalue, but not to other kinds of prvalues; those are covered in paragraph 4. This would be less confusing if paragraph 3 only dealt with binding rvalue references to glvalues and left all discussion of prvalues to paragraph 4, which adequately handles the class and array cases as well.

Notes from the May, 2015 meeting:

CWG reaffirmed the status quo for dynamic_cast but felt that const_cast should be changed to permit binding an rvalue reference to types that have associated memory (class and array types).




2243. Incorrect use of implicit conversion sequence

Section: 7.6.1.9  [expr.static.cast]     Status: drafting     Submitter: Hubert Tong     Date: 2016-03-08

The term “implicit conversion sequence” is now used in some non-call contexts (e.g., 7.6.1.9 [expr.static.cast] paragraph 4, 7.6.16 [expr.cond] paragraph 4, 7.6.10 [expr.eq] paragraph 4) ) and it is not clear that the current definition is suited for these additional uses. In particular, passing an argument in a function call is always copy-initialization, but some of these contexts require consideration of direct-initialization.

Notes from the December, 2016 teleconference:

The problem is that overload resolution relies on copy initalization and thus does not describe direct initialization. See also issue 1781.




901. Deleted operator delete

Section: 7.6.2.8  [expr.new]     Status: drafting     Submitter: John Spicer     Date: 20 May, 2009

It is not clear from 7.6.2.8 [expr.new] whether a deleted operator delete is referenced by a new-expression in which there is no initialization or in which the initialization cannot throw an exception, rendering the program ill-formed. (The question also arises as to whether such a new-expression constitutes a “use” of the deallocation function in the sense of 6.3 [basic.def.odr].)

Notes from the July, 2009 meeting:

The rationale for defining a deallocation function as deleted would presumably be to prevent such objects from being freed. Treating the new-expression as a use of such a deallocation function would mean that such objects could not be created in the first place. There is already an exemption from freeing an object if “a suitable deallocation function [cannot] be found;” a deleted deallocation function should be treated similarly.

Additional notes (April, 2023):

An additional use-case for a deleted deallocation function would be to ensure that the initialization of the object is not potentially-throwing.

For cases where the deallocation function is never called from the constructor, access checking for it should not be done.




2281. Consistency of aligned operator delete replacement

Section: 7.6.2.8  [expr.new]     Status: drafting     Submitter: Richard Smith     Date: 2016-06-27

We should require that a program that replaces the aligned form of operator delete also replaces the sized+aligned form. We only allow a program to replace the non-sized form without replacing the sized form for backwards compatibility. This is not needed for the alignment feature, which is new.

Notes from the March, 2018 meeting:

CWG concurred with the recommendation.




2623. Invoking destroying operator delete for constructor failure

Section: 7.6.2.8  [expr.new]     Status: drafting     Submitter: Blacktea Hamburger     Date: 2022-08-25

Subclause 7.6.2.8 [expr.new] paragraph 28 specifies the lookup for the deallocation function that is invoked when the construction of the object in a new-expression exits via an exception. However, a destroying operator delete (6.7.5.5.3 [basic.stc.dynamic.deallocation]) should never be used, because the object in question has not yet been fully created.

Suggested resolution [SUPERSEDED]:

Change in 7.6.2.8 [expr.new] paragraph 28 as follows:

A declaration of a placement deallocation function matches the declaration of a placement allocation function if it has the same number of parameters and, after parameter transformations (9.3.4.6 [dcl.fct]), all parameter types except the first are identical. If the lookup finds a single matching deallocation function, that function will be called; otherwise, no deallocation function will be called. If the lookup finds a usual deallocation function and that function, considered as a placement deallocation function, would have been selected as a match for the allocation function, the program is ill-formed. For a non-placement allocation function, the normal deallocation function lookup is used to find the matching deallocation function (7.6.2.9 [expr.delete]) , except that any destroying operator delete (6.7.5.5.3 [basic.stc.dynamic.deallocation]) is ignored.



2013. Pointer subtraction in large array

Section: 7.6.6  [expr.add]     Status: drafting     Submitter: Jason Merrill     Date: 2014-10-02

The common code sequence used by most implementations for pointer subtraction involves subtracting the pointer values to determine the number of bytes and then shifting to scale for the size of the array element. This produces incorrect results when the difference in bytes is larger than can be represented by a ptrdiff_t. For example, assuming a 32-bit ptrdiff_t:

  int *a, *b;
  a = malloc(0x21000000 * sizeof(int));
  b = a + 0x21000000;
  printf("%lx\n", (long)(b - a));

This will typically print e1000000 instead of 21000000.

Getting the right answer would require using a more expensive code sequence. It would be better to make this undefined behavior.




2182. Pointer arithmetic in array-like containers

Section: 7.6.6  [expr.add]     Status: drafting     Submitter: Jonathan Wakely     Date: 2015-10-20

The current direction for issue 1776 (see paper P0137) calls into question the validity of doing pointer arithmetic to address separately-allocated but contiguous objects in a container like std::vector. A related question is whether there should be some allowance made for allowing pointer arithmetic using a pointer to a base class if the derived class is a standard-layout class with no non-static data members. It is possible that std::launder could play a part in the resolution of this issue.

Notes from the February, 2016 meeting:

This issue is expected to be resolved by the resolution of issue 1776. The major problem is when the elements of the vector contain constant or reference members; 6.7.3 [basic.life] paragraph 7 implies that pointer arithmetic leading to such an object produces undefined behavior, and CWG expects this to continue. Some changes to the interface of std::vector may be required, perhaps using std::launder as part of iterator processing.




2023. Composite reference result type of conditional operator

Section: 7.6.16  [expr.cond]     Status: drafting     Submitter: Daniel Krügler     Date: 2014-10-16

The conditional operator converts pointer operands to their composite pointer type (7.6.16 [expr.cond] bullets 6.3 and 6.4). Similar treatment should be afforded to operands of reference type.

See also issue 2018.




2316. Simplifying class conversions in conditional expressions

Section: 7.6.16  [expr.cond]     Status: drafting     Submitter: S. B. Tam     Date: 2016-08-16

According to 7.6.16 [expr.cond] paragraph 4,

Attempts are made to form an implicit conversion sequence from an operand expression E1 of type T1 to a target type related to the type T2 of the operand expression E2 as follows:

It seems that to satisfy the conditions in the first two sub-bullets, T2 must be a class type, in which case T2 is the same as the type described in the third sub-bullet, since the lvalue-to-rvalue conversion does not change types and the other two conversions do not apply to a class type. Thus, this bullet and sub-bullets could be simplified to:

Notes from the August, 2020 teleconference:

This issue and suggested resolution predate the resolution of issue 2321, which added the second sub-bullet (the citation above reflects the wording after adoption of issue 2321), giving the result the cv-qualification of T1 instead of that of T2. The suggested resolution would revert that accepted resolution.




1542. Compound assignment of braced-init-list

Section: 7.6.19  [expr.ass]     Status: drafting     Submitter: Mike Miller     Date: 2012-08-21

The specification of 7.6.19 [expr.ass] paragraph 9 is presumably intended to allow use of a braced-init-list as the operand of a compound assignment operator as well as a simple assignment operator, although the normative wording does not explicitly say so. (The example in that paragraph does include

  complex<double> z;
  z += { 1, 2 };      // meaning z.operator+=({1,2})

for instance, which could be read to imply compound assignment operators for scalar types as well.)

However, the details of how this is to be implemented are not clear. Paragraph 7 says,

The behavior of an expression of the form E1 op = E2 is equivalent to E1 = E1 op E2 except that E1 is evaluated only once.

Applying this pattern literally to a braced-init-list yields invalid code: x += {1} would become x = x + {1}, which is non-syntactic.

Another problem is how to apply the prohibition against narrowing conversions to a compound assignment. For example,

  char c;
  c += {1};

would presumably always be a narrowing error, because after integral promotions, the type of c+1 is int. The similar issue 1078 was classified as "NAD" because the workaround was simply to add a cast to suppress the error; however, there is no place to put a similar cast in a compound assignment.

Notes from the October, 2012 meeting:

The incorrect description of the meaning of a compound assignment with a braced-init-list should be fixed by CWG. The question of whether it makes sense to apply narrowing rules to such assignments is better addressed by EWG.

See also issue 2399.




1255. Definition problems with constexpr functions

Section: 7.7  [expr.const]     Status: drafting     Submitter: Nikolay Ivchenkov     Date: 2011-03-08

The current wording of the Standard is not sufficiently clear regarding the interaction of class scope (which treats the bodies of member functions as effectively appearing after the class definition is complete) and the use of constexpr member functions within the class definition in contexts requiring constant expressions. For example, an array bound cannot use a constexpr member function that relies on the completeness of the class or on members that have not yet been declared, but the current wording does not appear to state that.

Additional note (October, 2013):

This question also affects function return type deduction (the auto specifier) in member functions. For example, the following should presumably be prohibited, but the current wording is not clear:

  struct S {
    static auto f() {
      return 42;
    }
    auto g() -> decltype(f()) {
      return f();
    }
  };

CWG 2023-06-15

Definitions of member functions need an "as-needed" treatment. See issues 1890 and 2335.




2166. Unclear meaning of “undefined constexpr function”

Section: 7.7  [expr.const]     Status: drafting     Submitter: Howard Hinnant     Date: 2015-08-05

According to 7.7 [expr.const] bullet 2.3, an expression is a constant expression unless (among other reasons) it would evaluate

This does not address the question of the point at which a constexpr function must be defined. The intent, in order to allow mutually-recursive constexpr functions, was that the function must be defined prior to the outermost evaluation that eventually results in the invocation, but this is not clearly stated.




2186. Unclear point that “preceding initialization” must precede

Section: 7.7  [expr.const]     Status: drafting     Submitter: Hubert Tong     Date: 2015-10-24

Similar to the concern of issue 2166, the requirement of 7.7 [expr.const] bullet 2.7.1 for

does not specify the point at which the determination of “preceding initialization” is made: is it at the point at which the reference to the variable appears lexically, or is it the point at which the outermost constant evaluation occurs? There is implementation divergence on this point.




2656. Converting consteval lambda to function pointer in non-immediate context

Section: 7.7  [expr.const]     Status: drafting     Submitter: Hubert Tong     Date: 2022-11-11

Converting a consteval lambda to a function pointer in a non-immediate context should be immediately-escalating.

Currently, this is well-formed:

  auto x = &*[]() consteval { return 42; };

Suggested resolution:

Make the conversion function of a lambda whose call operator is an immediate function also an immediate function.




1680. Including <initializer_list> for range-based for

Section: 8.6.5  [stmt.ranged]     Status: drafting     Submitter: Richard Smith     Date: 2013-05-13

A simple example like

  int main() {
    int k = 0;
    for (auto x : { 1, 2, 3 })
      k += x;
    return k;
  }

requires that the <initializer_list> header be included, because the expansion of the range-based for involves a declaration of the form

  auto &&__range = { 1, 2, 3 };

and a braced-init-list causes auto to be deduced as a specialization of std::initializer_list. This seems unnecessary and could be eliminated by specifying that __range has an array type for cases like this.

(It should be noted that EWG is considering a proposal to change auto deduction for cases involving braced-init-lists, so resolution of this issue should be coordinated with that effort.)

Notes from the September, 2013 meeting:

CWG felt that this issue should be resolved by using the array variant of the range-based for implementation.




2115. Order of implicit destruction vs release of automatic storage

Section: 8.7  [stmt.jump]     Status: drafting     Submitter: Richard Smith     Date: 2015-04-16

The relative ordering between destruction of automatic variables on exit from a block and the release of the variables' storage is not specified by the Standard: are all the destructors executed first and then the storage released, or are they interleaved?

Notes from the February, 2016 meeting:

CWG agreed that the storage should persist until all destructions are complete, although the “as-if” rule would allow for unobservable optimizations of this ordering.




1223. Syntactic disambiguation and trailing-return-types

Section: 8.9  [stmt.ambig]     Status: drafting     Submitter: Michael Wong     Date: 2010-11-08

Because the restriction that a trailing-return-type can appear only in a declaration with “the single type-specifier auto” (9.3.4.6 [dcl.fct] paragraph 2) is a semantic, not a syntactic, restriction, it does not influence disambiguation, which is “purely syntactic” (8.9 [stmt.ambig] paragraph 3). Consequently, some previously unambiguous expressions are now ambiguous. For example:

struct A {
  A(int *);
  A *operator()(void);
  int B;
};

int *p;
typedef struct BB { int C[2]; } *B, C;

void foo() {
// The following line becomes invalid under C++0x:
  A (p)()->B;  // ill-formed function declaration

// In the following,
// - B()->C is either type-id or class member access expression
// - B()->C[1] is either type-id or subscripting expression
// N3126 subclause 8.2 [dcl.ambig.res] does not mention an ambiguity
// with these forms of expression
  A a(B ()->C);  // function declaration or object declaration
  sizeof(B ()->C[1]);  // sizeof(type-id) or sizeof on an expression
}

Notes from the March, 2011 meeting:

CWG agreed that the presence of auto should be considered in disambiguation, even though it is formally handled semantically rather than syntactically.

CWG 2023-05-12

Both 8.9 [stmt.ambig] and 9.3.3 [dcl.ambig.res] need to be adjusted.

CWG 2023-06-13

Addressed by paper P2915R0.




2117. Explicit specializations and constexpr function templates

Section: 9.2.6  [dcl.constexpr]     Status: drafting     Submitter: Faisal Vali     Date: 2015-04-26

According to 9.2.6 [dcl.constexpr] paragraph 6,

If no specialization of the template would satisfy the requirements for a constexpr function or constexpr constructor when considered as a non-template function or constructor, the template is ill-formed; no diagnostic required.

This should say “instantiated template specialization” instead of just “specialization” to clarify that an explicit specialization is not in view here.




1348. Use of auto in a trailing-return-type

Section: 9.2.9.6  [dcl.spec.auto]     Status: drafting     Submitter: Richard Smith     Date: 2011-08-16

It is not clear whether the auto specifier can appear in a trailing-return-type.




1670. auto as conversion-type-id

Section: 9.2.9.6  [dcl.spec.auto]     Status: drafting     Submitter: Richard Smith     Date: 2013-04-26

N3690 comment FI 4

The current wording allows something like

  struct S {
    operator auto() { return 0; }
  } s;

If it is intended to be permitted, the details of its handling are not clear. Also, a similar syntax has been discussed as a possible future extension for dealing with proxy types in deduction which, if adopted, could cause confusion.

Additional note, November, 2013:

Doubt was expressed during the 2013-11-25 drafting review teleconference as to the usefulness of this provision. It is therefore being left open for further consideration after C++14 is finalized.

Notes from the February, 2014 meeting:

CWG continued to express doubt as to the usefulness of this construct but felt that if it is permitted, the rules need clarification.

Additional note (December, 2021):

See duplicate issue 2493 for additional details.




1868. Meaning of “placeholder type”

Section: 9.2.9.6  [dcl.spec.auto]     Status: drafting     Submitter: Dawn Perchik     Date: 2014-02-13

9.2.9 [dcl.type] paragraph 2 describes the auto specifier as “a placeholder for a type to be deduced.” Elsewhere, the Standard refers to the type represented by the auto specifier as a “placeholder type.” This usage has been deemed confusing by some, requiring either a definition of one or both terms or rewording to avoid them.




1488. abstract-pack-declarators in type-ids

Section: 9.3.2  [dcl.name]     Status: drafting     Submitter: Richard Smith     Date: 2012-03-28

The grammar for type-id in 11.3 [class.name] paragraph 1 has two problems. First, the fact that we allow an abstract-pack-declarator makes some uses of type-id (template arguments, alignment specifiers, exception-specifications) ambiguous: T... could be parsed either as a type-id, including the ellipsis, or as the type-id T with a following ellipsis. There does not appear to be any rule to disambiguate these parses.

The other problem is that we do not allow parentheses in an abstract-pack-declarator, which makes

  template<typename...Ts> void f(Ts (&...)[4]);

ill-formed because (&...)() is not an abstract-pack-declarator. There is implementation variance on this point.




1001. Parameter type adjustment in dependent parameter types

Section: 9.3.4.6  [dcl.fct]     Status: drafting     Submitter: Jason Merrill     Date: 2009-11-08

According to 9.3.4.6 [dcl.fct] paragraph 5, top-level cv-qualifiers on parameter types are deleted when determining the function type. It is not clear how or whether this adjustment should be applied to parameters of function templates when the parameter has a dependent type, however. For example:

    template<class T> struct A {
       typedef T arr[3];
    };

    template<class T> void f(const typename A<T>::arr) { } // #1

    template void f<int>(const A<int>::arr);

    template <class T> struct B {
       void g(T);
    };

    template <class T> void B<T>::g(const T) { } // #2

If the const in #1 is dropped, f<int> has a parameter type of A* rather than the const A* specified in the explicit instantiation. If the const in #2 is not dropped, we fail to match the definition of B::g to its declaration.

Rationale (November, 2010):

The CWG agreed that this behavior is intrinsic to the different ways cv-qualification applies to array types and non-array types.

Notes, January, 2012:

Additional discussion of this issue arose regarding the following example:

    template<class T> struct A {
      typedef double Point[2];
      virtual double calculate(const Point point) const = 0;
    };

    template<class T> struct B : public A<T> {
      virtual double calculate(const typename A<T>::Point point) const {
        return point[0];
      }
    };

    int main() {
      B<int> b;
      return 0;
    }

The question is whether the member function in B<int> has the same type as that in A<int>: is the parameter-type-list instantiated directly (i.e., using the adjusted types) or regenerated from the individual parameter types?

(See also issue 1322.)




1668. Parameter type determination still not clear enough

Section: 9.3.4.6  [dcl.fct]     Status: drafting     Submitter: Daniel Krügler     Date: 2013-04-25

According to 9.3.4.6 [dcl.fct] paragraph 5,

The type of a function is determined using the following rules. The type of each parameter (including function parameter packs) is determined from its own decl-specifier-seq and declarator. After determining the type of each parameter, any parameter of type “array of T” or “function returning T” is adjusted to be “pointer to T” or “pointer to function returning T,” respectively. After producing the list of parameter types, any top-level cv-qualifiers modifying a parameter type are deleted when forming the function type. The resulting list of transformed parameter types and the presence or absence of the ellipsis or a function parameter pack is the function's parameter-type-list. [Note: This transformation does not affect the types of the parameters. For example, int(*)(const int p, decltype(p)*) and int(*)(int, const int*) are identical types. —end note]

This is not sufficiently clear to specify the intended handling of an example like

  void f(int a[10], decltype(a) *p );

Should the type of p be int(*)[10] or int**? The latter is the intended result, but the phrase “after determining the type of each parameter” makes it sound as if the adjustments are performed after all the parameter types have been determined from the decl-specifier-seq and declarator instead of for each parameter individually.

See also issue 1444.




2537. Overbroad grammar for parameter-declaration

Section: 9.3.4.6  [dcl.fct]     Status: drafting     Submitter: Davis Herring     Date: 2021-02-25

9.3.4.6 [dcl.fct] paragraph 3 specifies the grammar for parameter-declaration:

  parameter-declaration:
      attribute-specifier-seqopt thisopt decl-specifier-seq declarator
      attribute-specifier-seqopt thisopt decl-specifier-seq declarator = initializer-clause
      attribute-specifier-seqopt thisopt decl-specifier-seq abstract-declaratoropt
      attribute-specifier-seqopt thisopt decl-specifier-seq abstract-declaratoropt = initializer-clause

This is overly permissive; using a defining-type-specifier-seq instead of a decl-specifier-seq is sufficient.

Proposed resolution (November, 2022):

  1. Change in 9.2.2 [dcl.stc] paragraph 4 as follows:

    There can be no static function declarations within a block, nor any static function parameters.
  2. Change in 9.2.2 [dcl.stc] paragraph 5 as follows:

    The extern specifier shall not be used in the declaration of a class member or function parameter.
  3. Change in 9.2.4 [dcl.typedef] paragraph 1 as follows:

    The typedef specifier shall not be combined in a decl-specifier-seq with any other kind of specifier except a defining-type-specifier, and it shall not be used in the decl-specifier-seq of a parameter-declaration (9.3.4.6 [dcl.fct]) nor in the decl-specifier-seq of a function-definition (9.5 [dcl.fct.def]).
  4. Change in 9.2.8 [dcl.inline] paragraph 4 as follows:

    The inline specifier shall not appear on a block scope declaration or on the declaration of a function parameter.
  5. Change in 9.3.4.6 [dcl.fct] paragraph 3 as follows:

      parameter-declaration:
          attribute-specifier-seqopt thisopt decl-specifier-seq defining-type-specifier-seq declarator
          attribute-specifier-seqopt thisopt decl-specifier-seq defining-type-specifier-seq declarator = initializer-clause
          attribute-specifier-seqopt thisopt decl-specifier-seq defining-type-specifier-seq abstract-declaratoropt
          attribute-specifier-seqopt thisopt decl-specifier-seq defining-type-specifier-seq abstract-declaratoropt = initializer-clause
    

CWG 2023-02-07

Additional drafting is needed to address references to decl-specifier-seq in other parts of the standard. A list is here. Furthermore, reducing the grammar to a type-specifier-seq appears to be sufficient.




325. When are default arguments parsed?

Section: 9.3.4.7  [dcl.fct.default]     Status: drafting     Submitter: Nathan Sidwell     Date: 27 Nov 2001

The standard is not precise enough about when the default arguments of member functions are parsed. This leads to confusion over whether certain constructs are legal or not, and the validity of certain compiler implementation algorithms.

9.3.4.7 [dcl.fct.default] paragraph 5 says "names in the expression are bound, and the semantic constraints are checked, at the point where the default argument expression appears"

However, further on at paragraph 9 in the same section there is an example, where the salient parts are

  int b;
  class X {
    int mem2 (int i = b); // OK use X::b
    static int b;
  };
which appears to contradict the former constraint. At the point the default argument expression appears in the definition of X, X::b has not been declared, so one would expect ::b to be bound. This of course appears to violate 6.4.7 [basic.scope.class] paragraph 1(2) "A name N used in a class S shall refer to the same declaration in its context and when reevaluated in the complete scope of S. No diagnostic is required."

Furthermore 6.4.7 [basic.scope.class] paragraph 1(1) gives the scope of names declared in class to "consist not only of the declarative region following the name's declarator, but also of .. default arguments ...". Thus implying that X::b is in scope in the default argument of X::mem2 previously.

That previous paragraph hints at an implementation technique of saving the token stream of a default argument expression and parsing it at the end of the class definition (much like the bodies of functions defined in the class). This is a technique employed by GCC and, from its behaviour, in the EDG front end. The standard leaves two things unspecified. Firstly, is a default argument expression permitted to call a static member function declared later in the class in such a way as to require evaluation of that function's default arguments? I.e. is the following well formed?

  class A {
    static int Foo (int i = Baz ());
    static int Baz (int i = Bar ());
    static int Bar (int i = 5);
 };
If that is well formed, at what point does the non-sensicalness of
  class B {
    static int Foo (int i = Baz ());
    static int Baz (int i = Foo());
  };
become detected? Is it when B is complete? Is it when B::Foo or B::Baz is called in such a way to require default argument expansion? Or is no diagnostic required?

The other problem is with collecting the tokens that form the default argument expression. Default arguments which contain template-ids with more than one parameter present a difficulty in determining when the default argument finishes. Consider,

  template <int A, typename B> struct T { static int i;};
  class C {
    int Foo (int i = T<1, int>::i);
  };
The default argument contains a non-parenthesized comma. Is it required that this comma is seen as part of the default argument expression and not the beginning of another of argument declaration? To accept this as part of the default argument would require name lookup of T (to determine that the '<' was part of a template argument list and not a less-than operator) before C is complete. Furthermore, the more pathological
  class D {
    int Foo (int i = T<1, int>::i);
    template <int A, typename B> struct T {static int i;};
  };
would be very hard to accept. Even though T is declared after Foo, T is in scope within Foo's default argument expression.

Suggested resolution:

Append the following text to 9.3.4.7 [dcl.fct.default] paragraph 8.

The default argument expression of a member function declared in the class definition consists of the sequence of tokens up until the next non-parenthesized, non-bracketed comma or close parenthesis. Furthermore such default argument expressions shall not require evaluation of a default argument of a function declared later in the class.

This would make the above A, B, C and D ill formed and is in line with the existing compiler practice that I am aware of.

Notes from the October, 2005 meeting:

The CWG agreed that the first example (A) is currently well-formed and that it is not unreasonable to expect implementations to handle it by processing default arguments recursively.

Additional notes, May, 2009:

Presumably the following is ill-formed:

    int f(int = f());

However, it is not clear what in the Standard makes it so. Perhaps there needs to be a statement to the effect that a default argument only becomes usable after the complete declarator of which it is a part.

Notes from the August, 2011 meeting:

In addition to default arguments, commas in template argument lists also cause problems in initializers for nonstatic data members:

    struct S {
      int n = T<a,b>(c);  // ill-formed declarator for member b
                          // or template argument?
    };

(This is from #16 of the IssuesFoundImplementingC0x.pdf document on the Bloomington wiki.

Additional notes (August, 2011):

See also issues 1352 and 361.

Notes from the February, 2012 meeting:

It was decided to handle the question of parsing an initializer like T<a,b>(c) (a template-id or two declarators) in this issue and the remaining questions in issue 361. For this issue, a template-id will only be recognized if there is a preceding declaration of a template.

Additional note (November, 2020):

Paper P1787R6, adopted at the November, 2020 meeting, partially addresses this issue.




1580. Default arguments in explicit instantiations

Section: 9.3.4.7  [dcl.fct.default]     Status: drafting     Submitter: Daveed Vandevoorde     Date: 2012-10-29

It is not clear, either from 9.3.4.7 [dcl.fct.default] or 13.9.3 [temp.explicit], whether it is permitted to add a default argument in an explicit instantiation of a function template:

  template<typename T> void f(T, int) { }
  template void f<int>(int, int=0);  // Permitted?

Notes from the April, 2013 meeting:

The intent is to prohibit default arguments in explicit instantiations.




2327. Copy elision for direct-initialization with a conversion function

Section: 9.4  [dcl.init]     Status: drafting     Submitter: Richard Smith     Date: 2016-09-30

Consider an example like:

  struct Cat {};
  struct Dog { operator Cat(); };

  Dog d;
  Cat c(d);

This goes to 9.4 [dcl.init] bullet 17.6.2:

Otherwise, if the initialization is direct-initialization, or if it is copy-initialization where the cv-unqualified version of the source type is the same class as, or a derived class of, the class of the destination, constructors are considered. The applicable constructors are enumerated (12.2.2.4 [over.match.ctor]), and the best one is chosen through overload resolution (12.2 [over.match]). The constructor so selected is called to initialize the object, with the initializer expression or expression-list as its argument(s). If no constructor applies, or the overload resolution is ambiguous, the initialization is ill-formed.

Overload resolution selects the move constructor of Cat. Initializing the Cat&& parameter of the constructor results in a temporary, per 9.4.4 [dcl.init.ref] bullet 5.2.1.2. This precludes the possitiblity of copy elision for this case.

This seems to be an oversight in the wording change for guaranteed copy elision. We should presumably be simultaneously considering both constructors and conversion functions in this case, as we would for copy-initialization, but we'll need to make sure that doesn't introduce any novel problems or ambiguities.

See also issue 2311.

This issue is addressed by paper P2828.




2128. Imprecise rule for reference member initializer

Section: 9.4.2  [dcl.init.aggr]     Status: drafting     Submitter: Richard Smith     Date: 2015-05-19

According to 11.9.3 [class.base.init] paragraph 11,

A temporary expression bound to a reference member from a brace-or-equal-initializer is ill-formed. [Example:

  struct A {
    A() = default;          // OK
    A(int v) : v(v) { }     // OK
    const int& v = 42;      // OK
  };
  A a1;                     // error: ill-formed binding of temporary to reference
  A a2(1);                  // OK, unfortunately

end example]

The rule is intended to apply only if an actual initialization results in such a binding, but it could be read as applying to the declaration of A::v itself. It would be clearer if the restriction were moved into bullet 9.1, e.g.,




2149. Brace elision and array length deduction

Section: 9.4.2  [dcl.init.aggr]     Status: drafting     Submitter: Vinny Romano     Date: 2015-06-25

According to 9.4.2 [dcl.init.aggr] paragraph 4,

An array of unknown size initialized with a brace-enclosed initializer-list containing n initializer-clauses, where n shall be greater than zero, is defined as having n elements (9.3.4.5 [dcl.array]).

However, the interaction of this with brace elision is not clear. For instance, in the example in paragraph 7,

  struct X { int i, j, k = 42; };
  X a[] = { 1, 2, 3, 4, 5, 6 };
  X b[2] = { { 1, 2, 3 }, { 4, 5, 6 } };

a and b are said to have the same value, even though there are six initializer-clauses in the initializer list in a's initializer and two in b's initializer.

Similarly, 13.10.3.2 [temp.deduct.call] paragraph 1 says,

in the P'[N] case, if N is a non-type template parameter, N is deduced from the length of the initializer list

Should that take into account the underlying type of the array? For example,

  template<int N> void f1(const X(&)[N]);
  f1({ 1, 2, 3, 4, 5, 6 }); // Is N deduced to 2 or 6?

  template<int N> void f2(const X(&)[N][2]);
  f2({ 1, 2, 3, 4, 5, 6 }); // Is N deduced to 1 or 6?



1304. Omitted array bound with string initialization

Section: 9.4.3  [dcl.init.string]     Status: drafting     Submitter: Nikolay Ivchenkov     Date: 2011-04-26

The example in 9.4.3 [dcl.init.string] paragraph 1 says,

  char msg[] = "Syntax error on line %s\n";

shows a character array whose members are initialized with a string-literal. Note that because '\n' is a single character and because a trailing '\0' is appended, sizeof(msg) is 25.

However, there appears to be no normative specification of how the size of the array is to be calculated.




233. References vs pointers in UDC overload resolution

Section: 9.4.4  [dcl.init.ref]     Status: drafting     Submitter: Matthias Meixner     Date: 9 Jun 2000

There is an inconsistency in the handling of references vs pointers in user defined conversions and overloading. The reason for that is that the combination of 9.4.4 [dcl.init.ref] and 7.3.6 [conv.qual] circumvents the standard way of ranking conversion functions, which was probably not the intention of the designers of the standard.

Let's start with some examples, to show what it is about:

    struct Z { Z(){} };

    struct A {
       Z x;

       operator Z *() { return &x; }
       operator const Z *() { return &x; }
    };

    struct B {
       Z x;

       operator Z &() { return x; }
       operator const Z &() { return x; }
    };

    int main()
    {
       A a;
       Z *a1=a;
       const Z *a2=a; // not ambiguous

       B b;
       Z &b1=b;
       const Z &b2=b; // ambiguous
    }

So while both classes A and B are structurally equivalent, there is a difference in operator overloading. I want to start with the discussion of the pointer case (const Z *a2=a;): 12.2.4 [over.match.best] is used to select the best viable function. Rule 4 selects A::operator const Z*() as best viable function using 12.2.4.3 [over.ics.rank] since the implicit conversion sequence const Z* -> const Z* is a better conversion sequence than Z* -> const Z*.

So what is the difference to the reference case? Cv-qualification conversion is only applicable for pointers according to 7.3.6 [conv.qual]. According to 9.4.4 [dcl.init.ref] paragraphs 4-7 references are initialized by binding using the concept of reference-compatibility. The problem with this is, that in this context of binding, there is no conversion, and therefore there is also no comparing of conversion sequences. More exactly all conversions can be considered identity conversions according to 12.2.4.2.5 [over.ics.ref] paragraph 1, which compare equal and which has the same effect. So binding const Z* to const Z* is as good as binding const Z* to Z* in terms of overloading. Therefore const Z &b2=b; is ambiguous. [12.2.4.2.5 [over.ics.ref] paragraph 5 and 12.2.4.3 [over.ics.rank] paragraph 3 rule 3 (S1 and S2 are reference bindings ...) do not seem to apply to this case]

There are other ambiguities, that result in the special treatment of references: Example:

    struct A {int a;};
    struct B: public A { B() {}; int b;};

    struct X {
       B x;
       operator A &() { return x; }
       operator B &() { return x; }
    };

    main()
    {
       X x;
       A &g=x; // ambiguous
    }

Since both references of class A and B are reference compatible with references of class A and since from the point of ranking of implicit conversion sequences they are both identity conversions, the initialization is ambiguous.

So why should this be a defect?

So overall I think this was not the intention of the authors of the standard.

So how could this be fixed? For comparing conversion sequences (and only for comparing) reference binding should be treated as if it was a normal assignment/initialization and cv-qualification would have to be defined for references. This would affect 9.4.4 [dcl.init.ref] paragraph 6, 7.3.6 [conv.qual] and probably 12.2.4.3 [over.ics.rank] paragraph 3.

Another fix could be to add a special case in 12.2.4 [over.match.best] paragraph 1.

CWG 2023-06-13

It was noted that the second example is not ambiguous, because a derived-to-base conversion is compared against an identity conversion. However, 12.2.4.2.5 [over.ics.ref] paragraph 1 needs a wording fix so that it applies to conversion functions as well. CWG opined that the first example be made valid, by adding a missing tie-breaker for the conversion function case.




1414. Binding an rvalue reference to a reference-unrelated lvalue

Section: 9.4.4  [dcl.init.ref]     Status: drafting     Submitter: Mike Miller     Date: 2011-11-09

Currently an attempt to bind an rvalue reference to a reference-unrelated lvalue succeeds, binding the reference to a temporary initialized from the lvalue by copy-initialization. This appears to be intentional, as the accompanying example contains the lines

    int i3 = 2;
    double&& rrd3 = i3;  // rrd3 refers to temporary with value 2.0

This violates the expectations of some who expect that rvalue references can be initialized only with rvalues. On the other hand, it is parallel with the handling of an lvalue reference-to-const (and is handled by the same wording). It also can add efficiency without requiring existing code to be rewritten: the implicitly-created temporary can be moved from, just as if the call had been rewritten to create a prvalue temporary from the lvalue explicitly.

On a related note, assuming the binding is permitted, the intent of the overload tiebreaker found in 12.2.4.3 [over.ics.rank] paragraph 3 is not clear:

At question is what “to an rvalue” means here. If it is referring to the value category of the initializer itself, before conversions, then the supposed performance advantage of the binding under discussion does not occur because the competing rvalue and lvalue reference overloads will be ambiguous:

    void f(int&&);    // #1
    void f(const int&);
    void g(double d) {
        f(d);         // ambiguous: #1 does not bind to an rvalue
    }

On the other hand, if “to an rvalue” refers to the actual object to which the reference is bound, i.e., to the temporary in the case under discussion, the phrase would seem to be vacuous because an rvalue reference can never bind directly to an lvalue.

Notes from the February, 2012 meeting:

CWG agreed that the binding rules are correct, allowing creation of a temporary when binding an rvalue reference to a non-reference-related lvalue. The phrase “to an rvalue” in 12.2.4.3 [over.ics.rank] paragraph 3 is a leftover from before binding an rvalue reference to an lvalue was prohibited and should be removed. A change is also needed to handle the following case:

    void f(const char (&)[1]);         // #1
    template<typename T> void f(T&&);  // #2
    void g() {
      f("");                           //calls #2, should call #1
    }

Additional note (October, 2012):

Removing “to an rvalue,” as suggested, would have the effect of negating the preference for binding a function lvalue to an lvalue reference instead of an rvalue reference because the case would now fall under the preceding bullet of 12.2.4.3 [over.ics.rank] bullet 3.1, sub-bullets 4 and 5:

Two implicit conversion sequences of the same form are indistinguishable conversion sequences unless one of the following rules applies:

Presumably if the suggested resolution is adopted, the order of these two bullets should be inverted.




1827. Reference binding with ambiguous conversions

Section: 9.4.4  [dcl.init.ref]     Status: drafting     Submitter: Hubert Tong     Date: 2014-01-07

In the following case,

  struct A {
    operator int &&() const;
    operator int &&() volatile;
    operator long();
  };

  int main() {
    int &&x = A();
  }

the conversion for direct binding cannot be used because of the ambiguity, so indirect binding is used, which allows the use of the conversion to long in creating the temporary.

Is this intended? There is implementation variation.

Notes from the February, 2014 meeting:

CWG agreed that an ambiguity like this should make the initialization ill-formed instead of falling through to do indirect binding.




1996. Reference list-initialization ignores conversion functions

Section: 9.4.5  [dcl.init.list]     Status: drafting     Submitter: Richard Smith     Date: 2014-09-04

The specification for list-initialization of a reference does not consider the existence of conversion functions. Consequently, the following example is ill-formed:

  struct S { operator struct D &(); } s;
  D &d{s};



2144. Function/variable declaration ambiguity

Section: 9.5.1  [dcl.fct.def.general]     Status: drafting     Submitter: Richard Smith     Date: 2015-06-19

The following fragment,

  int f() {};

is syntactically ambiguous. It could be either a function-definition followed by an empty-declaration, or it could be a simple-declaration whose init-declarator has the brace-or-equal-initializer {}. The same is true of a variable declaration

  int a {};

since function-definition simply uses the term declarator in its production.




1854. Disallowing use of implicitly-deleted functions

Section: 9.5.2  [dcl.fct.def.default]     Status: drafting     Submitter: Richard Smith     Date: 2014-02-11

The resolution of issue 1778 means that whether an explicitly-defaulted function is deleted or not cannot be known until the end of the class definition. As a result, new rules are required to disallow references (in, e.g., decltype) to explicitly-defaulted functions that might later become deleted.

Notes from the June, 2014 meeting:

The approach favored by CWG was to make any reference to an explicitly-defaulted function ill-formed if it occurs prior to the end of the class definition.




2563. Initialization of coroutine result object

Section: 9.5.4  [dcl.fct.def.coroutine]     Status: drafting     Submitter: Tomasz Kamiński     Date: 2022-04-06     Liaison: EWG

Subclause 9.5.4 [dcl.fct.def.coroutine] paragraph 7 specifies:

The expression promise.get_return_object() is used to initialize the returned reference or prvalue result object of a call to a coroutine. The call to get_return_object is sequenced before the call to initial-suspend and is invoked at most once.

It is unclear:

There is implementation divergence.

Note that a user-defined conversion may be involved in the initialization of the coroutine's prvalue result object from get_return_object(). Note also that the return type of get_return_object might be non-copyable and non-movable. However, there are certain programming patterns that would benefit from a late-initialized return value.

See also compiler explorer.

Suggested resolution [SUPERSEDED]:

Change in 9.5.4 [dcl.fct.def.coroutine] paragraph 7 as follows:

The expression promise.get_return_object() is used to initialize the The returned reference or prvalue result object of a call to a coroutine is copy-initialized with promise.get_return_object(). The call to get_return_object initialization is sequenced before the call to initial-suspend and is invoked at most once.

Additional notes (January, 2023)

See also clang bug report #56532.

Forwarded to EWG with paper issue 1414, by decision of the CWG chair.

EWG 2023-02-06

EWG agrees that get_return_object is invoked outside of the try-block and that, if a conversion is needed, the return value of get_return_object is considered an xvalue that is later converted to the result object.




1485. Out-of-class definition of member unscoped opaque enumeration

Section: 9.7.1  [dcl.enum]     Status: drafting     Submitter: Richard Smith     Date: 2012-03-26

The scope in which the names of enumerators are entered for a member unscoped opaque enumeration is not clear. According to 9.7.1 [dcl.enum] paragraph 10,

Each enum-name and each unscoped enumerator is declared in the scope that immediately contains the enum-specifier.

In the case of a member opaque enumeration defined outside its containing class, however, it is not clear whether the enumerator names are declared in the class scope or in the lexical scope containing the definition. Declaring them in the class scope would be a violation of 11.4 [class.mem] paragraph 1:

The member-specification in a class definition declares the full set of members of the class; no member can be added elsewhere.

Declaring the names in the lexical scope containing the definition would be contrary to the example in 13.7.2.6 [temp.mem.enum] paragraph 1:

  template<class T> struct A {
    enum E : T;
  };
  A<int> a;
  template<class T> enum A<T>::E : T { e1, e2 };
  A<int>::E e = A<int>::e1;

There also appear to be problems with the rules for dependent types and members of the current instantiation.

Notes from the October, 2012 meeting:

CWG agreed that an unscoped opaque enumeration in class scope should be forbidden.




2131. Ambiguity with opaque-enum-declaration

Section: 9.7.1  [dcl.enum]     Status: drafting     Submitter: Richard Smith     Date: 2015-05-28

The declaration

  enum E;

is ambiguous: it could be either a simple-declaration comprising the elaborated-type-specifier enum E and no init-declarator-list, or it could be an opaque-enum-declaration with an omitted enum-base (both of which are ill-formed, for different reasons).

(See also issue 2363.)




2505. Nested unnamed namespace of inline unnamed namespace

Section: 9.8.2.2  [namespace.unnamed]     Status: drafting     Submitter: Nathan Sidwell     Date: 2021-11-22

According to 9.8.2.2 [namespace.unnamed] paragraph 1,

An unnamed-namespace-definition behaves as if it were replaced by

where inline appears if and only if it appears in the unnamed-namespace-definition and all occurrences of unique in a translation unit are replaced by the same identifier, and this identifier differs from all other identifiers in the translation unit.

The use of a single identifier for all occurrences of unique within a translation unit leads to problems when an inline unnamed namespace contains a nested unnamed namespace, e.g.,

    inline namespace {
      namespace { }
    }

In this case, the unnamed namespace cannot be reopened because the lookup for unique finds both the outer and inner namespaces and is thus ambiguous.

Suggested resolution:

Change 9.8.2.2 [namespace.unnamed] paragraph 1 as follows:

...where inline appears if and only if it appears in the unnamed-namespace-definition and all occurrences of unique in each scope in a translation unit are replaced by the same scope-specific identifier, and this identifier differs from all other identifiers in the translation unit.

Notes from the December, 2021 teleconference:

The suggested resolution deals specifically with unnamed namespaces, but there are related examples that do not involve unnamed namespaces. The problem needs to be solved more generally in the specification of lookup.




2555. Ineffective redeclaration prevention for using-declarators

Section: 9.9  [namespace.udecl]     Status: drafting     Submitter: Christof Meerwald     Date: 2022-03-23

Consider:

  template<int I>
  struct C { };

  struct B
  {
    C<1> foo();
    C<1> bar();
  };

  struct D : B
  {
    using B::foo;
    C<2> foo(this B &);

    using B::bar;
    C<2> bar(this D &);
  };

  struct DD : D
  {
    using D::foo;
    using D::bar;
  };

  void bar(D d, DD dd)
  {
    d.foo();
    dd.foo();

    d.bar();
    dd.bar();
  }

Which functions are called?

Subclause 9.9 [namespace.udecl] paragraph 11 specifies:

The set of declarations named by a using-declarator that inhabits a class C does not include member functions and member function templates of a base class that correspond to (and thus would conflict with) a declaration of a function or function template in C.

The definition of "corresponds" considers the type of the implicit object parameter, which is a deviation from the status quo ante for a simple example like this one:

  struct B {
    void f();    // #1
  };
  struct D : B {
    void f();
    using B::f;  // should not name #1
  };

Suggested resolution:

Change in 9.9 [namespace.udecl] paragraph 11 as follows:

The set of declarations named by a using-declarator that inhabits a class C does not include member functions and member function templates of a base class that, when considered as members of C, correspond to (and thus would conflict with) a declaration of a function or function template in C.

[ Example:

  struct B {
    virtual void f(int);
    virtual void f(char);
    void g(int);
    void h(int);
    void i();
    void j();
  };

  struct D : B {
    using B::f;
    void f(int);   // OK, D::f(int) overrides B::f(int)
  
    using B::g;
    void g(char);  // OK
  
    using B::h;
    void h(int);   // OK, D::h(int) hides B::h(int)

    using B::i;
    void i(this B &);  // OK

    using B::j;
    void j(this D &);  // OK, D::j() hides B::j()
  };

  void k(D* p)
  {
    p->f(1);        // calls D::f(int)
    p->f('a');      // calls B::f(char)
    p->g(1);        // calls B::g(int)
    p->g('a');      // calls D::g(char)
    p->i();         // calls B::i, because B::i as a member of D is a better match than D::i
    p->j();         // calls D::j
  }
  ...



1817. Linkage specifications and nested scopes

Section: 9.11  [dcl.link]     Status: drafting     Submitter: Richard Smith     Date: 2013-12-04

According to 9.1 [dcl.pre] paragraph 2,

Unless otherwise stated, utterances in Clause 9 [dcl.dcl] about components in, of, or contained by a declaration or subcomponent thereof refer only to those components of the declaration that are not nested within scopes nested within the declaration.

This contradicts the intent of 9.11 [dcl.link] paragraph 4, which says,

In a linkage-specification, the specified language linkage applies to the function types of all function declarators, function names with external linkage, and variable names with external linkage declared within the linkage-specification.

Also, one of the comments in the example in paragraph 4 is inconsistent with the intent:

  extern "C" {
    static void f4(); // the name of the function f4 has
                      // internal linkage (not C language
                      // linkage) and the function's type
                      // has C language linkage.
  }

  extern "C" void f5() {
    extern void f4(); // OK: Name linkage (internal)
                      // and function type linkage (C
                      // language linkage) gotten from
                      // previous declaration.
  }

The language linkage for the block-scope declaration of f4 is presumably determined by the fact that it appears in a C-linkage function, not by the previous declaration.

Proposed resolution (February, 2014):

Change 9.11 [dcl.link] paragraph 4 as follows:

Linkage specifications nest. When linkage specifications nest, the innermost one determines the language linkage. A linkage specification does not establish a scope. A linkage-specification shall occur only in namespace scope (6.4 [basic.scope]). In a linkage-specification, the specified language linkage applies to the function types of all function declarators, function names with external linkage, and variable names with external linkage declared within the linkage-specification, including those appearing in scopes nested inside the linkage specification and not inside a nested linkage-specification. [Example:

...

  extern "C" {
    static void f4(); // the name of the function f4 has
                      // internal linkage (not C language
                      // linkage) and the function's type
                      // has C language linkage.
  }

  extern "C" void f5() {
    extern void f4(); // OK: Name linkage (internal)
                      // and function type linkage (C
                      // language linkage) gotten from
                      // previous declaration.; function type
                      // linkage (C language
                      // linkage) gotten
                      // from linkage specification
  }

Additional note, November, 2014:

The issue has been returned to "drafting" status to clarify the circumstances under which a preceding declaration supplies the language linkage for a declaration (for example, not when the declaration uses a typedef, which carries the language linkage, but only when the declaration uses a function declarator).




1706. alignas pack expansion syntax

Section: 9.12.1  [dcl.attr.grammar]     Status: drafting     Submitter: Daveed Vandevoorde     Date: 2013-06-26

The grammar for alignment-specifier in 9.12.1 [dcl.attr.grammar] paragraph 1 is:

where the ellipsis indicates pack expansion. Naively, one would expect that the expansion would result in forms like

    alignas()
    alignas(1, 2)
    alignas(int, double)

but none of those forms is given any meaning by the current wording. Instead, 13.7.4 [temp.variadic] paragraph 4 says,

In an alignment-specifier (9.12.2 [dcl.align]); the pattern is the alignment-specifier without the ellipsis.

Presumably this means that something like alignas(T...) would expand to something like

    alignas(int) alignas(double)

This is counterintuitive and should be reexamined.

See also messages 24016 through 24021.

Notes from the February, 2014 meeting:

CWG decided to change the pack expansion of alignas so that the type-id or assignment-expression is repeated inside the parentheses and to change the definition of alignas to accept multiple arguments with the same meaning as multiple alignas specifiers.




2223. Multiple alignas specifiers

Section: 9.12.2  [dcl.align]     Status: drafting     Submitter: Mike Herrick     Date: 2016-01-12

According to 9.12.2 [dcl.align] paragraph 4,

The alignment requirement of an entity is the strictest non-zero alignment specified by its alignment-specifiers, if any; otherwise, the alignment-specifiers have no effect.

It is not clear whether this applies to specifiers within a single declaration, or if it is intended to apply to the union of all declarations.

Similarly, paragraph 6 says,

If the defining declaration of an entity has an alignment-specifier, any non-defining declaration of that entity shall either specify equivalent alignment or have no alignment-specifier. Conversely, if any declaration of an entity has an alignment-specifier, every defining declaration of that entity shall specify an equivalent alignment. No diagnostic is required if declarations of an entity have different alignment-specifiers in different translation units.

This only talks about agreement between definitions and non-defining declarations. What about an example where an entity is not defined but is declared with different alignment-specifiers?

  struct alignas(16) A;
  struct alignas(32) A;

If A is not defined, is this, or should it be, ill-formed?

Notes from the February, 2017 meeting:

CWG agreed that the intent of the wording is that the “strictest” requirement is intended to apply to a single declaration, and the requirement for compatibility should apply to all declarations, whether the entity is defined or not.




2607. Visibility of enumerator names

Section: 10.2  [module.interface]     Status: drafting     Submitter: Richard Smith     Date: 2022-06-28

Consider:

  // module interface unit
  export module M;
  export enum E : int;
  enum E : int { e };

  // other translation unit
  import M;
  auto a = E::e;  // #1: OK?
  auto b = e;     // #2: OK?

It is unclear whether the enumerator name e is or ought to be visible in the other translation unit.

See also issues 2588 (friend declarations) and 2480.

CWG 2022-11-10

See 10.2 [module.interface] paragraph 7.




1890. Member type depending on definition of member function

Section: 11.4  [class.mem]     Status: drafting     Submitter: Hubert Tong     Date: 2014-03-07

Consider an example like:

  struct A {
    struct B {
      auto foo() { return 0; }
    };
    decltype(B().foo()) x;
  };

There does not appear to be a prohibition of cases like this, where the type of a member depends on the definition of a member function.

(See also issues 1360, 1397, and 2335.)

Additional notes (January, 2023):

The following example might be related:

  #include <type_traits>

  struct Bar {
    struct Baz {
      int a = 0;
    };
    static_assert(std::is_default_constructible_v<Baz>);
  };



1623. Deleted default union constructor and member initializers

Section: 11.4.5  [class.ctor]     Status: drafting     Submitter: Vinny Romano     Date: 2013-02-15

According to 11.4.5 [class.ctor] paragraph 5,

A defaulted default constructor for class X is defined as deleted if:

Because the presence of a non-static data member initializer is the moral equivalent of a mem-initializer, these rules should probably be modified not to define the generated constructor as deleted when a union member has a non-static data member initializer. (Note the non-normative references in 11.5 [class.union] paragraphs 2-3 and 9.2.9.2 [dcl.type.cv] paragraph 2 that would also need to be updated if this restriction is changed.)

It would also be helpful to add a requirement to 11.5 [class.union] requiring either a non-static data member initializer or a user-provided constructor if all the members of the union have const-qualified types.

On a more general note, why is the default constructor defined as deleted just because a member has a non-trivial default constructor? The union itself doesn't know which member is the active one, and default construction won't initialize any members (assuming no brace-or-equal-initializer). It is up to the “owner” of the union to control the lifetime of the active member (if any), and requiring a user-provided constructor is forcing a design pattern that doesn't make sense. Along the same lines, why is the default destructor defined as deleted just because a member has a non-trivial destructor? I would agree with this restriction if it only applied when the union also has a user-provided constructor.

See also issues 1460, 1562, 1587, and 1621.




1808. Constructor templates vs default constructors

Section: 11.4.5  [class.ctor]     Status: drafting     Submitter: Richard Smith     Date: 2013-11-12

It is not clear when, if ever, a constructor template can be considered to provide a default constructor. For example:

  struct A {
    template<typename ...T> A(T...); // #1
    A(std::initializer_list<long>);  // #2
  };
  A a{};

According to 9.4.5 [dcl.init.list] paragraph 3, A will be value-initialized if it has a default constructor, and there is implementation divergence whether this example calls #1 or #2.

Similarly, for an example like

  struct B {
    template<typename T=int> B(T = 0);
  };

it is not completely clear whether a default constructor should be implicitly declared or not.

More generally, do utterances in the Standard concerning “constructors” also apply to constructor templates?

Notes from the February, 2014 meeting:

One possibility discussed was that we may need to change places that explicitly refer to a default constructor to use overload resolution, similar to the change that was made a few years ago with regard to copy construction vs “copy constructor.” One additional use of “default constructor” is in determining the triviality of a class, but it might be a good idea to remove the concept of a trivial class altogether. This possibility will be explored.

Notes from the February, 2016 meeting:

CWG reaffirmed the direction from the preceding note and also determined that the presence of a constructor template should suppress implicit declaration of a default constructor.




2799. Inheriting default constructors

Section: 11.4.5.2  [class.default.ctor]     Status: drafting     Submitter: Hubert Tong     Date: 2017-09-01

Consider:

  struct A { int n; };
  struct B : A {
    using A::A;
    B(int);
  };

Does B have a default constructor?

Suggested resolution [SUPERSEDED]:

  1. Change in 9.9 [namespace.udecl] paragraph 4 as follows:

    If a constructor or assignment operator brought from a base class into a derived class has the signature of a default constructor or copy/move constructor or assignment operator for the derived class (11.4.5.2 [class.default.ctor], 11.4.5.3 [class.copy.ctor], 11.4.6 [class.copy.assign]), the using-declaration does not by itself suppress the implicit declaration of the derived class member; the member from the base class is hidden or overridden by the implicitly-declared copy/move constructor or assignment operator special member function of the derived class, as described below.
  2. Change in 11.4.5.2 [class.default.ctor] paragraph 1 as follows:

    A default constructor for a class X is a constructor of class X for which each parameter that is not a function parameter pack has a default argument (including the case of a constructor with no parameters). If there is no user-declared constructor for class X, or if X inherits (9.9 [namespace.udecl]) one or more default constructors and there is no user-declared default constructor for X, a non-explicit constructor having no parameters is implicitly declared as defaulted (9.5 [dcl.fct.def]). An implicitly-declared default constructor is an inline public member of its class.

Proposed resolution [SUPERSEDED]:

(This also resolves issue 2632.)

  1. Change in 9.9 [namespace.udecl] paragraph 4 as follows:

    If a constructor or assignment operator brought from a base class into a derived class has the signature of a copy/move constructor or assignment operator for the derived class (11.4.5.3 [class.copy.ctor], 11.4.6 [class.copy.assign]), the using-declaration does not by itself suppress the implicit declaration of the derived class member; the member from the base class is hidden or overridden by the implicitly-declared copy/move constructor or assignment operator of the derived class, as described below. [ Note: A using-declarator that names a member function of a base class does not suppress the implicit declaration of a special member function in the derived class, even if their signatures are the same (11.4.5.2 [class.default.ctor], 11.4.5.3 [class.copy.ctor], 11.4.6 [class.copy.assign]). -- end note ]
  2. Add a new paragraph before 11.4.1 [class.mem.general] paragraph 2 as follows:

    ... For any other member-declaration, each declared entity that is not an unnamed bit-field (11.4.10 [class.bit]) is a member of the class, termed a user-declared member, and each such member-declaration shall either declare at least one member name of the class or declare at least one unnamed bit-field.
  3. Change in 11.4.5.2 [class.default.ctor] paragraph 1 as follows:

    A default constructor for a class X is a constructor of class X for which each parameter that is not a function parameter pack has a default argument (including the case of a constructor with no parameters). If there is no a class X does not have a user-declared constructor for class X, or if X inherits (9.9 [namespace.udecl]) one or more default constructors and X does not have a user-declared default constructor, a non-explicit constructor having no parameters is implicitly declared as defaulted (9.5 [dcl.fct.def]). An implicitly-declared default constructor is an inline public member of its class. [ Example:
      struct A {};
      struct B {};
      struct C : A, B {
        using A::A, B::B;
        C(int);
      };
      C c;     // OK
    
      struct X { X(int = 0, int = 0); };  // #1
      struct Y { Y(int = 0); };           // #2
      struct Z : X, Y {
        using X::X, Y::Y;
      };
      Z z2(1, 1);   // OK, invokes X(1, 1) and Y()
      Z z1(1);      // error: ambiguous between #1 and #2
      Z z0;         // OK, invokes X() and Y()
    
    
    -- end example ]
  4. Change in 11.4.5.3 [class.copy.ctor] paragraph 6 as follows:

    If the class definition does not explicitly declare have a user-declared copy constructor, a non-explicit one is declared implicitly. ...
  5. Change in 11.4.5.3 [class.copy.ctor] paragraph 8 as follows:

    If the definition of a class X does not explicitly declare have a user-declared move constructor, a non-explicit one will be implicitly declared as defaulted if and only if ...
  6. Add a new paragraph before 11.4.5.3 [class.copy.ctor] paragraph 11 as follows:

    [ Note: A using-declaration in a derived class C that names a constructor from a base class never suppresses the implicit declaration of a copy/move constructor of C, even if the base class constructor would be a copy or move constructor if declared as a member of C. -- end note]

    A copy/move constructor for class X is trivial if it is not user-provided and if: ...

  7. Change in 11.4.6 [class.copy.assign] paragraph 2 as follows:

    If the class definition does not explicitly declare have a user-declared copy assignment operator, one is declared implicitly. If the class definition declares has a user-declared move constructor or move assignment operator, the implicitly declared copy assignment operator is defined as deleted; otherwise, it is defaulted (9.5 [dcl.fct.def]). The latter case is deprecated if the class has a user-declared copy constructor or a user-declared destructor (D.8 [depr.impldec]). ...

Additional notes (November, 2023)

How does access checking interact with the proposed resolution above?

  struct B {
  protected:
    B(int = 0);
  };
  struct A : B {
    using B::B;
    A(void *);
  };
  A a;       // okay?
  A aa(42);  // not okay

CWG 2023-11-06

CWG resolved not to declare a default constructor in the derived class, but instead apply the usual rules for inherited constructors for this case. The wording should be change so that the presence of a default constructor is never checked, in particular for 11.2 [class.prop], vacuous initialization, and default initialization.




1092. Cycles in overload resolution during instantiation

Section: 11.4.5.3  [class.copy.ctor]     Status: drafting     Submitter: Jason Merrill     Date: 2010-07-15

Moving to always doing overload resolution for determining exception specifications and implicit deletion creates some unfortunate cycles:

    template<typename T> struct A {
       T t;
    };

    template <typename T> struct B {
       typename T::U u;
    };

    template <typename T> struct C {
       C(const T&);
    };

    template <typename T> struct D {
       C<B<T> > v;
    };

    struct E {
       typedef A<D<E> > U;
    };

    extern A<D<E> > a;
    A<D<E> > a2(a);

If declaring the copy constructor for A<D<E>> is part of instantiating the class, then we need to do overload resolution on D<E>, and thus C<B<E>>. We consider C(const B<E>&), and therefore look to see if there's a conversion from C<B<E>> to B<E>, which instantiates B<E>, which fails because it has a field of type A<D<E>> which is already being instantiated.

Even if we wait until A<D<E>> is considered complete before finalizing the copy constructor declaration, declaring the copy constructor for B<E> will want to look at the copy constructor for A<D<E>>, so we still have the cycle.

I think that to avoid this cycle we need to short-circuit consideration of C(const T&) somehow. But I don't see how we can do that without breaking

    struct F {
       F(F&);
    };

    struct G;
    struct G2 {
       G2(const G&);
    };

    struct G {
       G(G&&);
       G(const G2&);
    };

    struct H: F, G { };

    extern H h;
    H h2(h);

Here, since G's move constructor suppresses the implicit copy constructor, the defaulted H copy constructor calls G(const G2&) instead. If the move constructor did not suppress the implicit copy constructor, I believe the implicit copy constructor would always be viable, and therefore a better match than a constructor taking a reference to another type.

So perhaps the answer is to reconsider that suppression and then disqualify any constructor taking (a reference to) a type other than the constructor's class from consideration when looking up a subobject constructor in an implicitly defined constructor. (Or assignment operator, presumably.)

Another possibility would be that when we're looking for a conversion from C<B<E>> to B<E> we could somehow avoid considering, or even declaring, the B<E> copy constructor. But that seems a bit dodgy.

Additional note (October, 2010):

An explicitly declared move constructor/op= should not suppress the implicitly declared copy constructor/op=; it should cause it to be deleted instead. This should prevent a member function taking a (reference to) an un-reference-related type from being chosen by overload resolution in a defaulted member function.

And we should clarify that member functions taking un-reference-related types are not even considered during overload resolution in a defaulted member function, to avoid requiring their parameter types to be complete.




1548. Copy/move construction and conversion functions

Section: 11.4.5.3  [class.copy.ctor]     Status: drafting     Submitter: Nikolay Ivchenkov     Date: 2012-09-02

The current wording of 11.4.5.3 [class.copy.ctor] paragraph 31 refers only to constructors and destructors:

When certain criteria are met, an implementation is allowed to omit the copy/move construction of a class object, even if the constructor selected for the copy/move operation and/or the destructor for the object have side effects.

However, in some cases (e.g., auto_ptr) a conversion function is also involved in the copying, and it could presumably also have visible side effects that would be eliminated by copy elision. (Some additional contexts that may also require changes in this regard are mentioned in the resolution of issue 535.)

Additional note (September, 2012):

The default arguments of an elided constructor can also have side effects and should be mentioned, as well; however, the elision should not change the odr-use status of functions and variables appearing in those default arguments.




1594. Lazy declaration of special members vs overload errors

Section: 11.4.5.3  [class.copy.ctor]     Status: drafting     Submitter: Richard Smith     Date: 2012-12-06

The implicit declaration of a special member function sometimes requires overload resolution, in order to select a special member to use for base classes and non-static data members. This can be required to determine whether the member is or would be deleted, and whether the member is trivial, for instance. The standard appears to require such overload resolution be performed at the end of the definition of the class, but in practice, implementations perform it lazily. This optimization appears to be non-conforming, in the case where overload resolution would hit an error. In order to enable this optimization, such errors should be “no diagnostic required.”

Additional note (March, 2013):

See also issue 1360.

Notes from the September, 2013 meeting:

The problem with this approach is that hard errors (not in the immediate context) can occur, affecting portability. There are some cases, such as a virtual assignment operator in the base class, where lazy evaluation cannot be done, so it cannot be mandated.




2203. Defaulted copy/move constructors and UDCs

Section: 11.4.5.3  [class.copy.ctor]     Status: drafting     Submitter: Vinny Romano     Date: 2015-11-20

Consider:

  struct A
  {
    A();
    A(A&);
    explicit A(int);
    operator int() const;
  };
  struct B
  {
    B(B&& other);
    A a;
  };
  B::B(B&& other) : a(static_cast<B&&>(other).a) {}
  // B::B(B&& other) = default; // ill-formed

  void f(B& b1)
  {
    B b2 = static_cast<B&&>(b1);
  }

The user-defined move constructor is well-formed because B::a can be initialized via A::operator int() and A::A(int); however, Clang and GCC believe a defaulted one would be ill-formed.

What about the following, which is considered well-formed by compilers and calls A::A(C&&)?

  struct C {};

  struct A : C
  {
    A();
    A(A&);
    A(C&&);
  };
  struct B
  {
    B(B&& other);
    A a;
  };

  B::B(B&& other) = default;



2264. Memberwise copying with indeterminate value

Section: 11.4.5.3  [class.copy.ctor]     Status: drafting     Submitter: Hubert Tong     Date: 2016-05-06

It appears that the following example may have unwanted undefined behavior in C++, although not in C:

  struct A { int x, y; };
  A passthrough(A a) { return a; }
  int main(void) {
   A a;
   a.x = 0;
   return passthrough(a).x;
  }

The default memberwise copying operation is not specified to be done in a way that is insensitive to indeterminate values.




1499. Missing case for deleted move assignment operator

Section: 11.4.6  [class.copy.assign]     Status: drafting     Submitter: John Spicer     Date: 2012-04-27

Bullet 4 of 11.4.5.3 [class.copy.ctor] paragraph 23 says that a defaulted copy/move assignment operator is defined as deleted if the class has

a non-static data member of class type M (or array thereof) that cannot be copied/moved because overload resolution (12.2 [over.match]), as applied to M's corresponding assignment operator, results in an ambiguity or a function that is deleted or inaccessible from the defaulted assignment operator

The intent of this is that if overload resolution fails to find a corresponding copy/move assignment operator that can validly be called to copy/move a member, the class's assignment operator will be defined as deleted. However, this wording does not cover an example like the following:

  struct A {
    A();
  };

  struct B {
    B();
    const A a;
  };

  typedef B& (B::*pmf)(B&&);

  pmf p =&B::operator=;

Here, the problem is simply that overload resolution failed to find a callable function, which is not one of the cases listed in the current wording. A similar problem exists for base classes in the fifth bullet.

Additional note (January, 2013):

A similar omission exists in paragraph 11 for copy constructors.




2329. Virtual base classes and generated assignment operators

Section: 11.4.6  [class.copy.assign]     Status: drafting     Submitter: Daveed Vandevoorde     Date: 2016-10-31

An example like the following,

  class A {
  private:
    A& operator=(const A&);
  };

  class B : virtual public A {
  public:
    B& operator = (const B& src);
  };

  class C: public B {
  public:
    void f(const C* psrc) {
      *this = *psrc;
    }
  };

is presumably well-formed, even though the copy assignment operator of A is inaccessible in C, because 11.4.6 [class.copy.assign] paragraph 12 says that only direct, not virtual, base class object assignment operators are invoked by the generated assignment operator (although there is implementation divergence on this question).

Should the example also be well-formed if A were a direct virtual base of C? That is, if a direct virtual base also has an indirect derivation path, its direct derivation can be ignored for generated assignment operators.

Possibly relevant to this question is the permission for an implementation to assign virtual base class objects more than once:

It is unspecified whether subobjects representing virtual base classes are assigned more than once by the implicitly-defined copy/move assignment operator.



1977. Contradictory results of failed destructor lookup

Section: 11.4.7  [class.dtor]     Status: drafting     Submitter: Gabriel Dos Reis     Date: 2014-07-21

According to 11.4.7 [class.dtor] paragraph 12,

At the point of definition of a virtual destructor (including an implicit definition (11.4.5.3 [class.copy.ctor])), the non-array deallocation function is looked up in the scope of the destructor's class (6.5.2 [class.member.lookup]), and, if no declaration is found, the function is looked up in the global scope. If the result of this lookup is ambiguous or inaccessible, or if the lookup selects a placement deallocation function or a function with a deleted definition (9.5 [dcl.fct.def]), the program is ill-formed. [Note: This assures that a deallocation function corresponding to the dynamic type of an object is available for the delete-expression (11.4.11 [class.free]). —end note]

However, bullet 5.3 of that section says that such a lookup failure causes the destructor to be defined as deleted, rather than making the program ill-formed. It appears that paragraph 12 was overlooked when deleted functions were added to the language. See also 11.4.11 [class.free] paragraph 7.




2158. Polymorphic behavior during destruction

Section: 11.4.7  [class.dtor]     Status: drafting     Submitter: Richard Smith     Date: 2015-07-13

Consider the following example:

  #include <stdio.h>
  struct Base {
    Base *p;
    virtual void f() { puts("base"); }
    ~Base() {
      p->f();
    }
  };
  struct Derived : Base {
    Derived() { p = this; }
    void f() { puts("derived"); }
    void g() {
      p->f();
      delete this;
    }
  };
  void h() {
    Derived *p = new Derived;
    p->g();
  }

Should this have defined behavior? On the one hand, the Derived object is in its period of destruction, so the behavior of the p->f() call in the Base destructor should be to call Base::f(). On the other hand, p is a pointer to a Derived object whose lifetime has ended, and the rules in 6.7.3 [basic.life] don't appear to allow the call. (Calling this->f() from the Base destructor would be OK — the question is whether you can do that for a pointer that used to point to the derived object, or if you can only do it for a pointer that was “created” after the dynamic type of the object changed to be Base.)

If the above is valid, it has severe implications for devirtualization. The purpose of 6.7.3 [basic.life] paragraph 7 appears to be to allow an implementation to assume that if it will perform two loads of a constant field (for instance, a const member, the implicit pointer for a reference member, or a vptr), and the two loads are performed on the “same pointer value”, then they load the same value.

Should there be a rule for destructors similar to that of 11.4.5 [class.ctor] paragraph 12?

During the construction of a const object, if the value of the object or any of its subobjects is accessed through a glvalue that is not obtained, directly or indirectly, from the constructor's this pointer, the value of the object or subobject thus obtained is unspecified.



1283. Static data members of classes with typedef name for linkage purposes

Section: 11.4.9.3  [class.static.data]     Status: drafting     Submitter: Mike Miller     Date: 2011-03-29

According to 11.4.9.3 [class.static.data] paragraph 4,

Unnamed classes and classes contained directly or indirectly within unnamed classes shall not contain static data members.

There is no such restriction on member functions, and there is no rationale for this difference, given that both static data members and member functions can be defined outside a unnamed class with a typedef name for linkage purposes. (Issue 406 acknowledged the lack of rationale by removing the specious note in 11.4.9.3 [class.static.data] that attempted to explain the restriction but left the normative prohibition in place.)

It would be more consistent to remove the restriction for classes with a typedef name for linkage purposes.

Additional note (August, 2012):

It was observed that, since no definition of a const static data member is required if it is not odr-used, there is no reason to prohibit such members in an unnamed class even without a typedef name for linkage purposes.




1721. Diagnosing ODR violations for static data members

Section: 11.4.9.3  [class.static.data]     Status: drafting     Submitter: Mike Miller     Date: 2013-07-31

Describing the handling of static data members with brace-or-equal-initializers, 11.4.9.3 [class.static.data] paragraph 3 says,

The member shall still be defined in a namespace scope if it is odr-used (6.3 [basic.def.odr]) in the program and the namespace scope definition shall not contain an initializer.

The word “shall” implies a required diagnostic, but this is describing an ODR violation (the static data member might be defined in a different translation unit) and thus should be “no diagnostic required.”




2335. Deduced return types vs member types

Section: 11.4.9.3  [class.static.data]     Status: drafting     Submitter: John Spicer     Date: 2017-01-29

It is not clear how an example like the following should be treated:

  template <class ...> struct partition_indices {
    static auto compute_right () {}
    static constexpr auto right = compute_right;
  };
  auto foo () -> partition_indices<>;
  void f() {
    foo();
  };

The initialization of right is in a context that must be done during the initial parse of the class, but the function body of compute_right is not supposed to be evaluated until the class is complete. Current implementations appear to accept the template case but not the equivalent non-template case. It's not clear why those cases should be treated differently.

If you change the example to include a forward dependency in the body of compute_right, e.g.,

  template <int> struct X {};
  template <class T> struct partition_indices {
    static auto compute_right () { return X<I>(); }
    static constexpr auto right = compute_right;
    static constexpr int I = sizeof(T);
  };

  auto foo () -> partition_indices<int>;

  void f() {
    foo();
  };

current implementations reject the code, but it's not clear that there is a rationale for the different behavior.

Notes from the March, 2018 meeting:

It was proposed that one direction might be to disallow instantiating member functions while the containing class template is being instantiated. However, overnight implementation experience indicated that this approach breaks seemingly-innocuous and currently-accepted code like:

  template <class T> struct A {
    static constexpr int num() { return 42; }
    int ar[num()];
  };
  A<int> a;

There was divergence of opinion regarding whether the current rules describe the current behavior for the two original examples or whether additional explicit rules are needed to clarify the difference in behavior between template and non-template examples, as well as whether there should be a difference at all..

Notes from the June, 2018 meeting:

The consensus of CWG was to treat templates and classes the same by "instantiating" delayed-parse regions when they are needed instead of at the end of the class.

See also issue 1890.




1404. Object reallocation in unions

Section: 11.5  [class.union]     Status: drafting     Submitter: Nikolay Ivchenkov     Date: 2011-10-19

According to 11.5 [class.union] paragraph 4,

[Note: In general, one must use explicit destructor calls and placement new operators to change the active member of a union. —end note] [Example: Consider an object u of a union type U having non-static data members m of type M and n of type N. If M has a non-trivial destructor and N has a non-trivial constructor (for instance, if they declare or inherit virtual functions), the active member of u can be safely switched from m to n using the destructor and placement new operator as follows:

  u.m.~M();
  new (&u.n)  N;

end example]

This pattern is only “safe” if the original object that is being destroyed does not involve any const-qualified or reference types, i.e., satisfies the requirements of 6.7.3 [basic.life] paragraph 7, bullet 3:

Although paragraph 4 of 11.5 [class.union] is a note and an example, it should at least refer to the lifetime issues described in 6.7.3 [basic.life].

Additional note (October, 2013):

See also issue 1776, which suggests possibly changing the restriction in 6.7.3 [basic.life]. If such a change is made, this issue may become moot.




1702. Rephrasing the definition of “anonymous union”

Section: 11.5  [class.union]     Status: drafting     Submitter: Richard Smith     Date: 2013-06-17

11.5 [class.union] paragraph 5 defines an anonymous union as follows:

A union of the form

is called an anonymous union; it defines an unnamed object of unnamed type.

It is obviously intended that a declaration like

    static union { int i; float f; };

is a declaration of that form (cf paragraph 6, which requires the static keyword for anonymous unions declared in namespace scope). However, it would be clearer if the definition were recast in more descriptive terms, e.g.,

An anonymous union is an unnamed class that is defined with the class-key union in a simple-declaration in which the init-declarator-list is omitted. Such a simple-declaration is treated as if it contained a single declarator declaring an unnamed variable of the union's type.

(Note that this definition would require some additional tweaking to apply to class member anonymous union declarations, since simple-declarations are not included as member-declarations.)

As a related point, it is not clear how the following examples are to be treated, and there is implementation variance on some:

   void f() { thread_local union { int a; }; }
   void g() { extern union { int b; }; }
   thread_local union { int c; }; // static is implied by thread_local
   static thread_local union { int d; };
   static const union { int e = 0; }; // is e const? Clang says yes, gcc says no
   static constexpr union { int f = 0; };

Additional notes (July, 2023)

This issue is addressed by issue 2767.




2246. Access of indirect virtual base class constructors

Section: 11.8.3  [class.access.base]     Status: drafting     Submitter: Vinny Romano     Date: 2016-03-08

Consider this example from issue 7:

  class Foo { };
  class A : virtual private Foo { };
  class Bar : public A { }; 

This example should cause Bar's defaulted default constructor to be deleted, because it does not have access to the injected-class-name Foo.

Notes from the December, 2016 teleconference:

The injected-class-name is irrelevant to the example, which is ill-formed. The access should be permitted only if conversion of the this pointer to a pointer to the base class would succeed.




2588. friend declarations and module linkage

Section: 11.8.4  [class.friend]     Status: drafting     Submitter: Nathan Sidwell     Date: 2022-05-26     Liaison: EWG

Consider:

  export module Foo;
  class X {
    friend void f(X); // #1 linkage?
  };

Subclause 11.8.4 [class.friend] paragraph 4 gives #1 external linkage:

A function first declared in a friend declaration has the linkage of the namespace of which it is a member (6.6 [basic.link]).

(There is no similar provision for friend classes first declared in a class.)

However, 6.6 [basic.link] bullet 4.8 gives it module linkage:

... otherwise, if the declaration of the name is attached to a named module (10.1 [module.unit]) and is not exported (10.2 [module.interface]), the name has module linkage;

Subclause 10.2 [module.interface] paragraph 2 does not apply:

A declaration is exported if it is declared within an export-declaration and inhabits a namespace scope or it is

Also consider this related example:

  export module Foo;
  export class Y;
  // maybe many lines later, or even a different partition of Foo
  class Y {
    friend void f(Y); // #2 linkage?
  };

See issue 2607 for a similar question about enumerators.

Additional note (May, 2022):

Forwarded to EWG with paper issue 1253, by decision of the CWG chair.

EWG telecon 2022-06-09

Consensus: "A friend's linkage should be affected by the presence/absence of export on the containing class definition itself, but ONLY if the friend is a definition", pending confirmation by electronic polling.

Proposed resolution (June, 2022):

  1. Change in 6.6 [basic.link] paragraph 4 as follows:

    ... The name of an entity that belongs to a namespace scope that has not been given internal linkage above and that is the name of
    • a variable; or
    • a function; or
    • a named class (11.1 [class.pre]), or an unnamed class defined in a typedef declaration in which the class has the typedef name for linkage purposes (9.2.4 [dcl.typedef]); or
    • a named enumeration (9.7.1 [dcl.enum]), or an unnamed enumeration defined in a typedef declaration in which the enumeration has the typedef name for linkage purposes (9.2.4 [dcl.typedef]); or
    • an unnamed enumeration that has an enumerator as a name for linkage purposes (9.7.1 [dcl.enum]); or
    • a template
    has its linkage determined as follows:
    • if the entity is a function or function template first declared in a friend declaration and that declaration is a definition, the name has the same linkage, if any, as the name of the enclosing class (11.8.4 [class.friend]);
    • otherwise, if the entity is a function or function template declared in a friend declaration and a corresponding non-friend declaration is reachable, the name has the linkage determined from that prior declaration,
    • otherwise, if the enclosing namespace has internal linkage, the name has internal linkage;
    • otherwise, if the declaration of the name is attached to a named module (10.1 [module.unit]) and is not exported (10.2 [module.interface]), the name has module linkage;
    • otherwise, the name has external linkage.
  2. Remove 11.8.4 [class.friend] paragraph 4:

    A function first declared in a friend declaration has the linkage of the namespace of which it is a member (6.6 [basic.link]). Otherwise, the function retains its previous linkage (9.2.2 [dcl.stc]).

EWG electronic poll 2022-06

Consensus for "A friend's linkage should be affected by the presence/absence of export on the containing class definition itself, but ONLY if the friend is a definition (option #2, modified by Jason's suggestion). This resolves CWG2588." See vote.




472. Casting across protected inheritance

Section: 11.8.5  [class.protected]     Status: drafting     Submitter: Mike Miller     Date: 16 Jun 2004

Does the restriction in 11.8.5 [class.protected] apply to upcasts across protected inheritance, too? For instance,

    struct B {
        int i;
    };
    struct I: protected B { };
    struct D: I {
        void f(I* ip) {
            B* bp = ip;    // well-formed?
            bp->i = 5;     // aka "ip->i = 5;"
        }
    };

I think the rationale for the 11.8.5 [class.protected] restriction applies equally well here — you don't know whether ip points to a D object or not, so D::f can't be trusted to treat the protected B subobject consistently with the policies of its actual complete object type.

The current treatment of “accessible base class” in 11.8.3 [class.access.base] paragraph 4 clearly makes the conversion from I* to B* well-formed. I think that's wrong and needs to be fixed. The rationale for the accessibility of a base class is whether “an invented public member” of the base would be accessible at the point of reference, although we obscured that a bit in the reformulation; it seems to me that the invented member ought to be considered a non-static member for this purpose and thus subject to 11.8.5 [class.protected].

(See also issues 385 and 471.).

Notes from October 2004 meeting:

The CWG tentatively agreed that casting across protective inheritance should be subject to the additional restriction in 11.8.5 [class.protected].

Proposed resolution (April, 2011)

Change 11.8.3 [class.access.base] paragraph 4 as follows:

A base class B of N is accessible at R, if

[Example:

    class B {
    public:
      int m;
    };

    class S: private B {
      friend class N;
    };
    class N: private S {
      void f() {
        B* p = this;    // OK because class S satisfies the fourth condition
                        // above: B is a base class of N accessible in f() because
                        // B is an accessible base class of S and S is an accessible
                        // base class of N.
      }
    };

    class N2: protected B { };

    class P2: public N2 {
      void f2(N2* n2p) {
        B* bp = n2p;    // error: invented member would be protected and naming
                        // class N2 not the same as or derived from the referencing
                        // class P2
        n2p->m = 0;     // error (cf 11.8.5 [class.protected]) for the same reason
      }
    };

end example]




1883. Protected access to constructors in mem-initializers

Section: 11.8.5  [class.protected]     Status: drafting     Submitter: Daveed Vandevoorde     Date: 2014-02-26

According to 11.8.5 [class.protected] paragraph 1, except when forming a pointer to member,

All other accesses involve a (possibly implicit) object expression (7.6.1.5 [expr.ref]).

It is not clear that this is strictly true for the invocation of a base class constructor from a mem-initializer. A wording tweak may be advisable.




2187. Protected members and access via qualified-id

Section: 11.8.5  [class.protected]     Status: drafting     Submitter: Hubert Tong     Date: 2015-10-16

The following line in the example in 11.8.5 [class.protected] paragraph 1 is no longer allowed following the change from issue 1873:

  class B {
  protected:
    int i;
    static int j;
  };
  // ...
  class D2 : public B {
    friend void fr(B*, D1*, D2*);
    void mem(B*, D1*);
  };
  void fr(B* pb, D1* p1, D2* p2) {
    // ...
    p2->B::i = 4;  // OK (access through a D2, even though naming class is B)
    // ...
  }

The example line ought to work, but none of the bullets in 11.8.3 [class.access.base] paragraph 5 apply:

A member m is accessible at the point R when named in class N if

One aproach might be that 11.8.3 [class.access.base] bullet 5.3 should also consider friends of a class P derived from N where P is the type of the object expression (if any) or a base class thereof, and m as a member of P is public, protected, or private.




2056. Member function calls in partially-initialized class objects

Section: 11.9.3  [class.base.init]     Status: drafting     Submitter: Richard Smith     Date: 2014-12-11

According to 11.9.3 [class.base.init] paragraph 16,

Member functions (including virtual member functions, 11.7.3 [class.virtual]) can be called for an object under construction. Similarly, an object under construction can be the operand of the typeid operator (7.6.1.8 [expr.typeid]) or of a dynamic_cast (7.6.1.7 [expr.dynamic.cast]). However, if these operations are performed in a ctor-initializer (or in a function called directly or indirectly from a ctor-initializer) before all the mem-initializers for base classes have completed, the result of the operation is undefined.

The example in that paragraph reads, in significant part,

  class B {
  public:
    int f();
  };

  class C {
  public:
    C(int);
  };

  class D : public B, C {
  public:
    D() : C(f())  // undefined: calls member function
                  // but base \tcode{C} not yet initialized
    {}
  };

However, the construction of B, the object for which the member function is being called) has completed its construction, so it is not clear why this should be undefined behavior.

(See also issue 1517.)




2403. Temporary materialization and base/member initialization

Section: 11.9.3  [class.base.init]     Status: drafting     Submitter: Daveed Vandevoorde     Date: 2018-12-11

Given the following example,

  struct Noncopyable {
    Noncopyable();
    Noncopyable(const Noncopyable &) = delete;
  };

  Noncopyable make(int kind = 0);

  struct AsBase : Noncopyable {
    AsBase() : Noncopyable(make()) {} // #1
  };

  struct AsMember {
    Noncopyable nc;
    AsMember() : nc(make()) { }  // #2?
  };

All implementations treat #1 as an error, invoking the deleted copy constructor, while #2 is accepted. It's not clear from the current wording why they should be treated differently.

Additional note (August, 2022):

If there are concerns about reuse of tail padding in #1, requiring a copy for some implementation reason, similar concerns should apply to #2 if the data member is declared with [[no_unique_address]].

Furthermore, the following example using a delegating constructor shows implementation divergence:

struct Noncopyable {
  Noncopyable();
  Noncopyable(const Noncopyable &) = delete;
  Noncopyable(int) : Noncopyable(Noncopyable()) {} // #3?
};



1517. Unclear/missing description of behavior during construction/destruction

Section: 11.9.5  [class.cdtor]     Status: drafting     Submitter: Daniel Krügler     Date: 2012-07-07

The current wording of 11.9.5 [class.cdtor] paragraph 4 does not describe the behavior of calling a virtual function in a mem-initializer for a base class, only for a non-static data member. Also, the changes for issue 1202 should have been, but were not, applied to the description of the behavior of typeid and dynamic_cast in paragraphs 5 and 6.

In addition, the resolution of issue 597 allowing the out-of-lifetime conversion of pointers/lvalues to non-virtual base classes, should have been, but were not, applied to paragraph 3.

(See also issue 2056.)

Proposed resolution (August, 2013):

  1. Change 11.9.5 [class.cdtor] paragraph 1 as follows:

  2. For an object with a non-trivial constructor, referring to any non-static member or virtual base class of the object before the constructor begins execution results in undefined behavior. For an object with a non-trivial destructor, referring to any non-static member or virtual base class of the object after the destructor finishes execution results in undefined behavior. [Example:
      struct X { int i; };
      struct Y : X { Y(); };                       // non-trivial
      struct A { int a; };
      struct B : public virtual A { int j; Y y; }; // non-trivial
    
      extern B bobj;
      B* pb = &bobj;                               // OK
      int* p1 = &bobj.a;                           // undefined, refers to base class member
      int* p2 = &bobj.y.i;                         // undefined, refers to member's member
    
      A* pa = &bobj;                               // undefined, upcast to a virtual base class type
      B bobj;                                      // definition of bobj
    
      extern X xobj;
      int* p3 = &xobj.i;                           //OK, X is a trivial class
      X xobj;
    
  3. Change 11.9.5 [class.cdtor] paragraphs 3-6 as follows:

  4. To explicitly or implicitly convert a pointer (a glvalue) referring to an object of class X to a pointer (reference) to a direct or indirect virtual base class B of X, the construction of X and the construction of all of its direct or indirect bases that directly or indirectly derive from for which B is a direct or indirect virtual base shall have started and the destruction of these classes shall not have completed, otherwise the conversion results in undefined behavior. To form a pointer to (or access the value of) a direct non-static member...

    Member functions, including virtual functions (11.7.3 [class.virtual]), can be called during construction or destruction (11.9.3 [class.base.init]). When a virtual function is called directly or indirectly from a constructor or from a destructor, including during the construction or destruction of the class's non-static data members, and the object to which the call applies is the object (call it x) under construction or destruction, the function called is the final overrider in the constructor's or destructor's class and not one overriding it in a more-derived class. If the virtual function call uses an explicit class member access (7.6.1.5 [expr.ref]) and the object expression refers to the complete object of x or one of that object's base class subobjects but not to x or one of its base class subobjects, the behavior is undefined. The period of construction of an object or subobject whose type is a class type C begins immediately after the construction of all its base class subobjects is complete and concludes when the last constructor of class C exits. The period of destruction of an object or subobject whose type is a class type C begins when the destructor for C begins execution and concludes immediately before beginning the destruction of its base class subobjects. A polymorphic operation is a virtual function call (7.6.1.3 [expr.call]), the typeid operator (7.6.1.8 [expr.typeid]) when applied to a glvalue of polymorphic type, or the dynamic_cast operator (7.6.1.7 [expr.dynamic.cast]) when applied to a pointer to or glvalue of a polymorphic type. A polymorphic operand is the object expression in a virtual function call or the operand of a polymorphic typeid or dynamic_cast.

    During the period of construction or period of destruction of an object or subobject whose type is a class type C (call it x), the effect of performing a polymorphic operation in which the polymorphic operand designates x or a base class subobject thereof is as if the dynamic type of the object were class C. [Footnote: This is true even if C is an abstract class, which cannot be the type of a most-derived object. —end footnote] If a polymorphic operand refers to an object or subobject having class type C before its period of construction begins or after its period of destruction is complete, the behavior is undefined. [Note: This includes the evaluation of an expression appearing in a mem-initializer of C in which the mem-initializer-id designates C or one of its base classes. —end note] [Example:

      struct V {
        V();
        V(int);
        virtual void f();
        virtual void g();
      };
    
      struct A : virtual V {
        virtual void f();
        virtual int h();
        A() : V(h()) { }     // undefined behavior: virtual function h called
                             // before A's period of construction begins
      };
    
      struct B : virtual V {
        virtual void g();
        B(V*, A*);
      };
    
      struct D : A, B {
        virtual void f();
        virtual void g();
        D() : B((A*)this, this) { }
      };
    
      B::B(V* v, A* a) {
        f();                 // calls V::f, not A::f
        g();                 // calls B::g, not D::g
        v->g();              // v is base of B, the call is well-defined, calls B::g
        a->f();              // undefined behavior, a's type not a base of B
        typeid(*this);       // type_info for B
        typeid(*v);          // well-defined: *v has type V, a base of B,
                             // so its period of construction is complete;
                             // yields type_info for B
        typeid(*a);          // undefined behavior: A is not a base of B,
                             // so its period of construction has not begun
        dynamic_cast<B*>(v); // well-defined: v has type V*, V is a base of B,
                             // so its period of construction is complete;
                             // results in this
        dynamic_cast<B*>(a); // undefined behavior: A is not a base of B,
                             // so its period of construction has not begun
      }
    

    end example]

    The typeid operator (7.6.1.8 [expr.typeid]) can be used during construction or destruction (11.9.3 [class.base.init]). When typeid is used in a constructor (including the mem-initializer or brace-or-equal-initializer for a non-static data member) or in a destructor, or used in a function called (directly or indirectly) from a constructor or destructor, if the operand of typeid refers to the object under construction or destruction, typeid yields the std::type_info object representing the constructor or destructor's class. If the operand of typeid refers to the object under construction or destruction and the static type of the operand is neither the constructor or destructor's class nor one of its bases, the result of typeid is undefined.

    dynamic_casts (7.6.1.7 [expr.dynamic.cast]) can be used during construction or destruction (11.9.3 [class.base.init]). When a dynamic_cast is used in a constructor (including the mem-initializer or brace-or-equal-initializer for a non-static data member) or in a destructor, or used in a function called (directly or indirectly) from a constructor or destructor, if the operand of the dynamic_cast refers to the object under construction or destruction, this object is considered to be a most derived object that has the type of the constructor or destructor's class. If the operand of the dynamic_cast refers to the object under construction or destruction and the static type of the operand is not a pointer to or object of the constructor or destructor's own class or one of its bases, the dynamic_cast results in undefined behavior. [Example:

      struct V {
        virtual void f();
      };
    
      struct A : virtual V { };
    
      struct B : virtual V {
        B(V*, A*);
      };
    
      struct D : A, B {
        D() : B((A*)this, this) { }
      };
    
      B::B(V* v, A* a) {
        typeid(*this);       // type_info for B
        typeid(*v);          // well-defined: *v has type V, a base of B
                             // yields type_info for B
        typeid(*a);          // undefined behavior: type A not a base of B
        dynamic_cast<B*>(v); // well-defined: v of type V*, V base of B
                             // results in B*
        dynamic_cast<B*>(a); // undefined behavior,
                             // a has type A*, A not a base of B
    

    end example]




1278. Incorrect treatment of contrived object

Section: 12.2.2.2.2  [over.call.func]     Status: drafting     Submitter: Nikolay Ivchenkov     Date: 2011-03-27

Footnote 127 of 12.2.2.2.2 [over.call.func] paragraph 3 reads,

An implied object argument must be contrived to correspond to the implicit object parameter attributed to member functions during overload resolution. It is not used in the call to the selected function. Since the member functions all have the same implicit object parameter, the contrived object will not be the cause to select or reject a function.

It is not true that “the member functions all have the same implicit object parameter.” This statement does not take into account member functions brought into the class by using-declarations or cv-qualifiers and ref-qualifiers on the non-static member functions:

    struct B
    {
      char f();         // B &
    };

    struct D : B
    {
      using B::f;
      long f();         // D &

      char g() const;   // D const &
      long g();         // D &

      char h() &;       // D &
      long h() &&;      // D &&
    };

    int main()
    {
      // D::f() has better match than B::f()
      decltype(D().f()) *p1 = (long *)0;

      // D::g() has better match than D::g() const
      decltype(D().g()) *p2 = (long *)0;

      // D::h() & is not viable function
      // D::h() && is viable function
      decltype(D().h()) *p3 = (long *)0;
    }

The value category of a contrived object expression is not specified by the rules and, probably, cannot be properly specified in presence of ref-qualifiers, so the statement “the contrived object will not be the cause to select or reject a function” should be normative rather than informative:

    struct X
    {
      static void f(double) {}
      void f(int) & {}
      void f(int) && {}
    };

    int main()
    {
      X::f(0); // ???
    }



2564. Conversion to function pointer with an explicit object parameter

Section: 12.2.2.2.3  [over.call.object]     Status: drafting     Submitter: Christof Meerwald     Date: 2022-04-11

Subclause 12.2.2.2.3 [over.call.object] paragraph 2 considers only those conversion funtions matching a particular grammar pattern. This unintendedly excludes conversion functions with an explicit object parameter (and, as a pre-existing defect, noexcept conversion functions):

In addition, for each non-explicit conversion function declared in T of the form
operator conversion-type-id ( ) cv-qualifier-seqopt ref-qualifieropt noexcept-specifieropt attribute-specifier-seqopt ;
where the optional cv-qualifier-seq is the same cv-qualification as, or a greater cv-qualification than, cv, and where conversion-type-id denotes the type “pointer to function of (P1 , . . . , Pn ) returning R”, or the type “reference to pointer to function of (P1 , . . . , Pn ) returning R”, or the type “reference to function of (P1 , . . . , Pn ) returning R”, a surrogate call function with the unique name call-function and having the form
R call-function ( conversion-type-id F, P1 a1 , ... , Pn an ) { return F (a1 , . . . , an ); }
is also considered as a candidate function. Similarly, surrogate call functions are added to the set of candidate functions for each non-explicit conversion function declared in a base class of T provided the function is not hidden within T by another intervening declaration. [ Footnote: ...]

For example, there is implementation divergence in handling this example:

  using fn_t = void();
  struct C {
    operator fn_t * (this C const &);
  };

  void foo(C c) {
    c();
  }



2089. Restricting selection of builtin overloaded operators

Section: 12.2.2.3  [over.match.oper]     Status: drafting     Submitter: Hubert Tong     Date: 2015-02-26

The candidates selected by 12.2.2.3 [over.match.oper] include built-in candidates that will result in an error if chosen; this was affirmed by issue 1687. As a result, t+u is ill-formed because it is resolved to the built-in operator+(int*,std::ptrdiff_t), although most implementations do not (yet) agree:

  struct Adaptor { Adaptor(int); };

  struct List { };
  void operator +(List &, Adaptor);

  struct DataType {
    operator int *() const = delete;
    operator List &() const;
  };

  struct Yea;
  struct Nay { int theNaysHaveIt; };

  template <typename T, typename U>
  Yea addCheck(int, T &&t, U &&u, char (*)[sizeof(t + u, 0)] = 0);

  template <typename T, typename U>
  Nay addCheck(void *, T &&t, U &&u);

  void test(DataType &data) { (void)sizeof(addCheck(0, data,
  0.).theNaysHaveIt); }

It might be better to adjust the candidate list in 12.2.2.4 [over.match.ctor] bullet 3.3.3 to allow conversion only on class types and exclude the second standard conversion sequence.




2028. Converting constructors in rvalue reference initialization

Section: 12.2.2.7  [over.match.ref]     Status: drafting     Submitter: Mitsuru Kariya     Date: 2014-10-25

Consider the following example:

  struct T {
    T() {}
    T(struct S&) {}
  };

  struct S {
    operator T() { return T(); }
  };

  int main()
  {
    S s;
    T&& t(s);  // #1
  }

Because there are two possible conversions from S to T, one by conversion function and the other by converting constructor, one might expect that the initialization at #1 would be ambiguous. However, 12.2.2.7 [over.match.ref] (used in the relevant bullet of 9.4.4 [dcl.init.ref], paragraph 5.2.1.2) only deals with conversion functions and ignores converting constructors.

Notes from the November, 2014 meeting:

CWG agreed that 9.4.4 [dcl.init.ref] should be changed to consider converting constructors in this case.




2108. Conversions to non-class prvalues in reference initialization

Section: 12.2.2.7  [over.match.ref]     Status: drafting     Submitter: Hubert Tong     Date: 2015-03-24

In 12.2.2.7 [over.match.ref], candidates that produce non-class prvalues are considered, although that seems to contradict what 9.4.4 [dcl.init.ref] says. See also issue 2077.




2194. Impossible case in list initialization

Section: 12.2.2.8  [over.match.list]     Status: drafting     Submitter: Robert Haberlach     Date: 2015-11-04

According to 12.2.2.8 [over.match.list] paragraph 1 says,

If the initializer list has no elements and T has a default constructor, the first phase is omitted.

However, this case cannot occur. If T is a non-aggregate class type with a default constructor and the initializer is an empty initializer list, the object will be value-constructed, per 9.4.5 [dcl.init.list] bullet 3.4. Overload resolution is only necessary if default-initialization (or a check of its semantic constraints) is implied, with the relevant section concerning candidates for overload resolution being 12.2.2.4 [over.match.ctor].

See also issue 1518.

Proposed resolution (January, 2017):

Change 12.2.2.8 [over.match.list] paragraph 1 as follows:

When objects of non-aggregate class type T are list-initialized such that 9.4.5 [dcl.init.list] specifies that overload resolution is performed according to the rules in this section, overload resolution selects the constructor in two phases:

If the initializer list has no elements and T has a default constructor, the first phase is omitted. In copy-list-initialization, if an explicit constructor is chosen...

Additional notes, February, 2017:

The statement of the issue is incorrect. In an example like

  struct A { A(); A(initializer_list<int>); };
  void f(A a);
  int main() { f({}); }

the rule in question is not used for the initialization of the parameter. However, it is used to determine whether a valid implicit conversion sequence exists for a. It is unclear whether an additional change to resolve this discrepancy is needed or not.




2467. CTAD for alias templates and the deducible check

Section: 12.2.2.9  [over.match.class.deduct]     Status: drafting     Submitter: Richard Smith     Date: 2019-08-12

Given the declarations

  template<typename T = int> using X = vector<int>;
  X x = {1, 2, 3};

  template<typename...> using Y = vector<int>;
  Y y = {1, 2, 3};

CTAD deduces vector<int>. Then we are asked to perform a check that the arguments of X and Y are deducible from vector<int>.

I think this check should succeed, deducing T = int in the first case and <pack> = <empty> in the second case, so both declarations should be valid. That seems consistent with what would happen for a non-alias with template parameters that CTAD can't deduce, where there is either a default template argument or the parameter is a pack. But what actually happens is that we're asked to form

  template<typename T> struct AA;
  template<typename T = int> struct AA<X<T>>;

and

  template<typename T> struct AA;
  template<typename ...Ts> struct AA<Y<Ts...>>;

However, both of those partial specializations are ill-formed: a partial specialization can't have default template arguments, and neither of these is more specialized than the primary template, because T / Ts are not used in deducible contexts.

I think we have the wrong model here, and should instead be considering (effectively) whether function template argument deduction would succeed for

  template<typename T> struct AA {};
  template<typename T = int> void f(AA<X<T>>);

and

  template<typename T> struct AA {};
  template<typename ...Ts> void f(AA<Y<Ts...>>);

respectively, when given an argument of type AA<deduced return type>. That is, get rid of the weird class template partial specialization restrictions, and instead add in the rules from function templates to use default template arguments and to default non-deduced packs to empty packs.




2471. Nested class template argument deduction

Section: 12.2.2.9  [over.match.class.deduct]     Status: drafting     Submitter: John Spicer     Date: 2021-01-26

Consider the following example:

  template<class T> struct S {
    template<class U> struct N {
      N(T) {}
      N(T, U) {}
      template<class V> N(V, U) {}
    };
  };
  S<int>::N x{2.0, 1};

The description of CTAD in 12.2.2.9 [over.match.class.deduct] doesn't really specify how nested classes work. If you are supposed to deduce all the enclosing class template arguments, the example is ill-formed because there is no way to deduce T. If you are supposed to consider S<int>::N as having a new constructor template, then it should probably be well-formed.

Notes from the March, 2021 teleconference:

CWG agreed that the intent is to use the partially-instantiated inner template with the explicitly-specified template argument int.




2319. Nested brace initialization from same type

Section: 12.2.4.2  [over.best.ics]     Status: drafting     Submitter: Richard Smith     Date: 2016-09-06

Consider:

  struct A { A(); } a;
  A a1 = {a}, a2 = {{a}}, a3 = {{{a}}};

a1 and a2 are valid, a3 is ill-formed, because 12.2.4.2 [over.best.ics] bullet 4.5 allows one pair of braces and 12.2.4.2.6 [over.ics.list] paragraph 2 allows a second pair of braces. The implicit conversion sequence from {{a}} to A is a user-defined conversion.

Prior to the list-initialization-from-same-type changes via issues 1467 and 2076, a2 was ill-formed like a3.

Is this intended, or did DR2076 not go far enough in reintroducing the restriction? Perhaps a more extreme rule, such as saying that a copy/move constructor is simply not a candidate for list-initialization from a list that contains one element that is itself a list, would work better?

Notes from the July, 2017 meeting:

CWG agreed that the a2 example should be ill-formed but that the a1 example must remain for C compatibility.




2525. Incorrect definition of implicit conversion sequence

Section: 12.2.4.2.1  [over.best.ics.general]     Status: drafting     Submitter: Jim X     Date: 2021-09-25

According to 12.2.4.2.1 [over.best.ics.general] paragraphs 1 and 9,

An implicit conversion sequence is a sequence of conversions used to convert an argument in a function call to the type of the corresponding parameter of the function being called. The sequence of conversions is an implicit conversion as defined in 7.3 [conv], which means it is governed by the rules for initialization of an object or reference by a single expression (9.4 [dcl.init], 9.4.4 [dcl.init.ref]).

If no sequence of conversions can be found to convert an argument to a parameter type, an implicit conversion sequence cannot be formed.

However, 7.3.1 [conv.general] paragraph 3 says,

An expression E can be implicitly converted to a type T if and only if the declaration T t=E; is well-formed, for some invented temporary variable t (9.4 [dcl.init]).

This definition is too restrictive in the context of overload resolution's implicit conversion sequences. The intent, as stated in 12.2.1 [over.match.general] note 1, is that overload resolution ignores some factors that would make such an initialization ill-formed, and these are applied only after the best match is determined:

[Note 1: The function selected by overload resolution is not guaranteed to be appropriate for the context. Other restrictions, such as the accessibility of the function, can make its use in the calling context ill-formed. —end note]

For example,

  struct A{
    A(int) = delete;
  };
  struct B{
     B(int) {}
  };
  void fun(A); // #1
  void fun(B); // #2
  int main() {
    fun(0);    // #3
  }

The intent is that overload #1 be viable with a valid implicit conversion sequence, making the call at #3 ambiguous, even though the hypothetical declaration

  A t = 1;

would be ill-formed.

Proposed resolution (approved by CWG 2022-12-02):

Change 12.2.4.2.1 [over.best.ics.general] paragraph 1, merging it with paragraph 2,as follows:

An implicit conversion sequence is a sequence of conversions used to convert an argument in a function call to the type of the corresponding parameter of the function being called. The sequence of conversions is an implicit conversion as defined in 7.3 [conv], which means; it is governed by thus based on the rules for initialization of an object or reference by a single expression (9.4 [dcl.init], 9.4.4 [dcl.init.ref]). Implicit, except that implicit conversion sequences are concerned only with the type, cv-qualification, and value category of the argument and how these are converted to match the corresponding properties of the parameter. [Note: ... ]

CWG 2023-02-06

Additional drafting is needed to cover e.g. conversions from literal 0 to null pointer constants.




2077. Overload resolution and invalid rvalue-reference initialization

Section: 12.2.4.2.5  [over.ics.ref]     Status: drafting     Submitter: Richard Smith     Date: 2015-01-29

The resolution of issue 1604 broke the following example:

  struct A {};
  struct B { operator const A() const; };
  void f(A const&);
  void f(A&&);

  int main() {
    B a;
    f(a);
  }

Overload resolution selects the A&& overload, but then initialization fails. This seems like a major regression; we're now required to reject

   std::vector<A> va;
   B b;
   va.push_back(b);

Should we update 12.2.4.2.5 [over.ics.ref] to match the changes made to 9.4.4 [dcl.init.ref]?

See also issue 2108.




1536. Overload resolution with temporary from initializer list

Section: 12.2.4.2.6  [over.ics.list]     Status: drafting     Submitter: Mike Miller     Date: 2012-08-14

In determining the implicit conversion sequence for an initializer list argument passed to a reference parameter, the intent is that a temporary of the appropriate type will be created and bound to the reference, as reflected in 12.2.4.2.6 [over.ics.list] paragraph 5:

Otherwise, if the parameter is a reference, see 12.2.4.2.5 [over.ics.ref]. [Note: The rules in this section will apply for initializing the underlying temporary for the reference. —end note]

However, 12.2.4.2.5 [over.ics.ref] deals only with expression arguments, not initializer lists:

When a parameter of reference type binds directly (9.4.4 [dcl.init.ref]) to an argument expression, the implicit conversion sequence is the identity conversion, unless the argument expression has a type that is a derived class of the parameter type, in which case the implicit conversion sequence is a derived-to-base Conversion (12.2.4.2 [over.best.ics])... If the parameter binds directly to the result of applying a conversion function to the argument expression, the implicit conversion sequence is a user-defined conversion sequence (12.2.4.2.3 [over.ics.user]), with the second standard conversion sequence either an identity conversion or, if the conversion function returns an entity of a type that is a derived class of the parameter type, a derived-to-base Conversion.

When a parameter of reference type is not bound directly to an argument expression, the conversion sequence is the one required to convert the argument expression to the underlying type of the reference according to 12.2.4.2 [over.best.ics]. Conceptually, this conversion sequence corresponds to copy-initializing a temporary of the underlying type with the argument expression. Any difference in top-level cv-qualification is subsumed by the initialization itself and does not constitute a conversion.

(Note in particular that the reference binding refers to 9.4.4 [dcl.init.ref], which also does not handle initializer lists, and not to 9.4.5 [dcl.init.list].)

Either 12.2.4.2.5 [over.ics.ref] needs to be revised to handle binding references to initializer list arguments or 12.2.4.2.6 [over.ics.list] paragraph 5 needs to be clearer on how the expression specification is intended to be applied to initializer lists.




2492. Comparing user-defined conversion sequences in list-initialization

Section: 12.2.4.2.6  [over.ics.list]     Status: drafting     Submitter: Jim X     Date: 2021-01-11

Consider the following example:

  #include <initializer_list>
  struct A{
    operator short(){
      return 0;
    }
  };
  struct B{
    operator bool(){
      return 0;
    }
  };
  void fun(std::initializer_list<int>){}
  void fun(std::initializer_list<bool>){}
  int main(){
    fun({A{},B{}});
  }

According to 12.2.4.2.6 [over.ics.list] paragraph 6,

Otherwise, if the parameter type is std::initializer_list<X> and all the elements of the initializer list can be implicitly converted to X, the implicit conversion sequence is the worst conversion necessary to convert an element of the list to X, or if the initializer list has no elements, the identity conversion. This conversion can be a user-defined conversion even in the context of a call to an initializer-list constructor.

In this example, all of the conversions from list elements to the initializer_list template argument type are user-defined conversions. According to 12.2.4.3 [over.ics.rank] bullet 3.3,

User-defined conversion sequence U1 is a better conversion sequence than another user-defined conversion sequence U2 if they contain the same user-defined conversion function or constructor or they initialize the same class in an aggregate initialization and in either case the second standard conversion sequence of U1 is better than the second standard conversion sequence of U2.

Since in both cases the two elements of the initializer-list argument involve different user-defined conversion functions, the two user-defined conversion sequences for the elements cannot be distinguished, so the determination of the “worst conversion” for the two candidates does not consider the second standard conversion sequence. This presumably makes it impossible to distinguish the conversion sequences for the two candidates in the function call, making the call ambiguous.

However, there is implementation divergence on the handling of this example, with g++ reporting an ambiguity and clang, MSVC, and EDG calling the int overload, presumably on the basis that short->int is a promotion while short->bool is a conversion.

Notes from the August, 2021 teleconference:

CWG agreed with the reasoning expressed in the analysis, that conversions involving different user-defined conversion functions cannot be compared, and thus the call is ambiguous. The use of the phrase “worst conversion” is insufficiently clear, however, and requires definition.

Proposed resolution, August, 2021:

Change 12.2.4.2.6 [over.ics.list] paragraphs 5 and 6 as follows:

Otherwise, if the parameter type is std::initializer_list<X> and either the initializer list is empty or all the elements of the initializer list can be implicitly converted to X, the implicit conversion sequence is the worst conversion worst conversion necessary to convert an element of the list to X, or if defined as follows. If the initializer list has no elements, the worst conversion is the identity conversion. Otherwise, the worst conversion is an implicit conversion sequence for a list element that is not better than any other implicit conversion sequence required by list elements, compared as described in 12.2.4.3 [over.ics.rank]. If more than one implicit conversion sequence satisfies this criterion, then if they are user-defined conversion sequences that do not all contain the same user-defined conversion function or constructor, the worst conversion sequence is the ambiguous conversion sequence (12.2.4.2.1 [over.best.ics.general]); otherwise, it is unspecified which of those conversion sequences is chosen as worst. This conversion can be a user-defined conversion even in the context of a call to an initializer-list constructor. [Example 2:

  void f(std::initializer_list<int>);
  f( {} );        // OK: f(initializer_list<int>) identity conversion
  f( {1,2,3} );   // OK: f(initializer_list<int>) identity conversion
  f( {'a','b'} ); // OK: f(initializer_list<int>) integral promotion
  f( {1.0} );     // error: narrowing

  struct A {
    A(std::initializer_list<double>);            // #1
    A(std::initializer_list<complex<double>>);   // #2
    A(std::initializer_list<std::string>);       // #3
  };
  A a{ 1.0,2.0 };        // OK, uses #1

  void g(A);
  g({ "foo", "bar" });   // OK, uses #3

  typedef int IA[3];
  void h(const IA&);
  h({ 1, 2, 3 });        // OK: identity conversion

  void x(std::initializer_list<int>);
  void x(std::initializer_list<bool>);
  struct S1 { operator short(); };
  struct S2 { operator bool(); };
  void y() {
    x({S1{}, S2{}});   // error: ambiguous. The ICSes for each list element are indistinguishable because
                       // they do not contain the same conversion function, so the worst conversion is
                       // the ambiguous conversion sequence.
  }

end example]

Otherwise, if the parameter type is “array of N X ” or “array of unknown bound of X”, if there exists an implicit conversion sequence from each element of the initializer list (and from {} in the former case if N exceeds the number of elements in the initializer list) to X, the implicit conversion sequence is the worst such implicit conversion sequence conversion necessary to convert an element of the list (including, if there are too few list elements, {}) to X, determined as described above for a std::initializer_list<X> with a non-empty initializer list.

CWG 2023-06-13

An ambiguous conversion for the function selected by overload resolution is ill-formed per 12.2.4.2.1 [over.best.ics.general]. Instead of attempting to define "worst conversion" (possibly with focusing on the second standard conversion sequence in user-defined conversions), it might be more consistent overall to use the rules for a succession of function arguments/parameters when comparing list-initializations.




2110. Overload resolution for base class conversion and reference/non-reference

Section: 12.2.4.3  [over.ics.rank]     Status: drafting     Submitter: Alexander Kulpin     Date: 2015-03-27

There are overload tiebreakers that order reference/nonreference and base/derived conversions, but how they relate is not specified. For example:

  struct A { A(); };
  struct B : A {};
  struct C : B {};

  void f1(B&);
  void f1(A);

  void f2(B);
  void f2(A&);

  int main()
  {
     C v;
     f1(v); // all compilers choose f1(B&)
     f2(v); // all compilers choose f2(B)
  }

The Standard does not appear to specify what happens in this case.




1989. Insufficient restrictions on parameters of postfix operators

Section: 12.4  [over.oper]     Status: drafting     Submitter: Richard Smith     Date: 2014-08-30

According to 12.4.7 [over.inc] paragraph 1,

The user-defined function called operator++ implements the prefix and postfix ++ operator. If this function is a non-static member function with no parameters, or a non-member function with one parameter, it defines the prefix increment operator ++ for objects of that type. If the function is a non-static member function with one parameter (which shall be of type int) or a non-member function with two parameters (the second of which shall be of type int), it defines the postfix increment operator ++ for objects of that type.

According to 12.4 [over.oper] paragraph 8,

Operator functions cannot have more or fewer parameters than the number required for the corresponding operator, as described in the rest of this subclause.

This does not rule out an operator++ with more than two parameters, however, since there is no corresponding operator.

One possibility might be to add a sentence like,

A function named operator++ shall declare either a prefix or postfix increment operator.



205. Templates and static data members

Section: Clause 13  [temp]     Status: drafting     Submitter: Mike Miller     Date: 11 Feb 2000

Static data members of template classes and of nested classes of template classes are not themselves templates but receive much the same treatment as template. For instance, Clause 13 [temp] paragraph 1 says that templates are only "classes or functions" but implies that "a static data member of a class template or of a class nested within a class template" is defined using the template-declaration syntax.

There are many places in the clause, however, where static data members of one sort or another are overlooked. For instance, Clause 13 [temp] paragraph 6 allows static data members of class templates to be declared with the export keyword. I would expect that static data members of (non-template) classes nested within class templates could also be exported, but they are not mentioned here.

Paragraph 8, however, overlooks static data members altogether and deals only with "templates" in defining the effect of the export keyword; there is no description of the semantics of defining a static data member of a template to be exported.

These are just two instances of a systematic problem. The entire clause needs to be examined to determine which statements about "templates" apply to static data members, and which statements about "static data members of class templates" also apply to static data members of non-template classes nested within class templates.

(The question also applies to member functions of template classes; see issue 217, where the phrase "non-template function" in 9.3.4.7 [dcl.fct.default] paragraph 4 is apparently intended not to include non-template member functions of template classes. See also issue 108, which would benefit from understanding nested classes of class templates as templates. Also, see issue 249, in which the usage of the phrase "member function template" is questioned.)

Notes from the 4/02 meeting:

Daveed Vandevoorde will propose appropriate terminology.




1463. extern "C" alias templates

Section: 13.1  [temp.pre]     Status: drafting     Submitter: Daveed Vandevoorde     Date: 2011-08-19     Liaison: EWG

Currently 13.1 [temp.pre] paragraph 6 forbids any template from having C linkage. Should alias templates be exempt from this prohibition, since they do not have any linkage?

Additional note, April, 2013:

It was suggested that relaxing this restriction for alias templates could provide a way of addressing the long-standing lack of a way of specifying a language linkage for a dependent function type (see issue 13).

Rationale (April, 2013):

CWG felt that this suggested use of alias templates should be considered in a broader context and thus was more appropriate for EWG.

EWG 2022-11-11

extern "C" on a template should be allowed, and should affect only calling convention, but not mangling. This is tracked in github issue cplusplus/papers#1373.




1444. Type adjustments of non-type template parameters

Section: 13.2  [temp.param]     Status: drafting     Submitter: Johannes Schaub     Date: 2012-01-15

The type adjustment of template non-type parameters described in 13.2 [temp.param] paragraph 8 appears to be underspecified. For example, implementations vary in their treatment of

  template<typename T, T[T::size]> struct A {};
  int dummy;
  A<int, &dummy> a;

and

  template<typename T, T[1]> struct A;
  template<typename T, T*> struct A {};
  int dummy;
  A<int, &dummy> a;

See also issues 1322 and 1668.

Additional note, February, 2021:

See the discussion regarding top-level cv-qualifiers on template parameters when determining the type in this compiler bug report.




1635. How similar are template default arguments to function default arguments?

Section: 13.2  [temp.param]     Status: drafting     Submitter: Richard Smith     Date: 2013-03-06

Default function arguments are instantiated only when needed. Is the same true of default template arguments? For example, is the following well-formed?

  #include <type_traits>

  template<class T>
  struct X {
    template<class U = typename T::type>
    static void foo(int){}
    static void foo(...){}
  };

  int main(){
    X<std::enable_if<false>>::foo(0);
  }

Also, is the effect on lookup the same? E.g.,

  struct S {
    template<typename T = U> void f();
    struct U {};
  };

Additional note (November, 2020):

Paper P1787R6, adopted at the November, 2020 meeting, partially addresses this issue.




2395. Parameters following a pack expansion

Section: 13.2  [temp.param]     Status: drafting     Submitter: Richard Smith     Date: 2018-12-03

The Standard is not clear, and there is implementation divergence, for an example like the following:

  template<class ...Types> struct Tuple_ { // _VARIADIC_TEMPLATE 
    template<Types ...T, int I> int f() {
      return sizeof...(Types);
    }
  };
  int main() {
    Tuple_<char,int> a;
    int b = a.f<1, 2, 3>();
  }

The question is whether the 3 is accepted as the argument for I or an error, exceeding the number of arguments for T, which is set as 2 by the template arguments for Tuple_. See also issue 2383 for a related example.




2043. Generalized template arguments and array-to-pointer decay

Section: 13.4.3  [temp.arg.nontype]     Status: drafting     Submitter: Richard Smith     Date: 2014-11-13

According to 13.4.3 [temp.arg.nontype] paragraph 1 (newly revised by the adoption of paper N4268),

For a non-type template-parameter of reference or pointer type, the value of the constant expression shall not refer to (or for a pointer type, shall not be the address of):

This change breaks an example like

   template<int *p> struct X {};
   int arr[32];
   X<arr> x;

because the array-to-pointer decay produces a pointer to the first element, which is a subobject.

Suggested resolution:

Change the referenced bullet to read:

Note that this resolution also allows an example like

    template<char &p> struct S { };
    char arr[2];
    S<arr[0]> s_arr;

which may not be exactly what we want.

See also issue 2401.




2049. List initializer in non-type template default argument

Section: 13.4.3  [temp.arg.nontype]     Status: drafting     Submitter: Ville Voutilainen     Date: 2014-11-20

According to 13.4.3 [temp.arg.nontype] paragraph 1,

A template-argument for a non-type template-parameter shall be a converted constant expression (7.7 [expr.const]) of the type of the template-parameter.

This does not permit an example like:

  template <int* x = {}> struct X {};

which seems inconsistent.

See also issues 2450 and 2459.




2401. Array decay vs prohibition of subobject non-type arguments

Section: 13.4.3  [temp.arg.nontype]     Status: drafting     Submitter: John Spicer     Date: 2019-02-06

Consider an example like:

  template <const char *N> struct A { static const int val; };

  template <const char *N> const int A<N>::val = 0;

  static const char c[2] = "";

  int main() {
    A<c> a;
    return A<c>::val;
  }

Formally, this appears to violate the prohibition of using the address of a subobject as a non-type template argument, since the array reference c in the argument decays to a pointer to the first element of the array. However, at least some implementations accept this example, and at least conceptually the template argument designates the complete object. Should an exception be made for the result of array decay?

See also issue 2043.

Notes from the July, 2019 meeting

CWG felt that the example should be allowed if the parameter type is a pointer to object type (thus prohibiting void*).




2459. Template parameter initialization

Section: 13.4.3  [temp.arg.nontype]     Status: drafting     Submitter: Davis Herring     Date: 2020-09-21

The initialization of template parameters is severely underspecified. The only descriptions in the existing wording that apply are that the argument is “[converted] to the type of the template-parameter” (13.6 [temp.type] bullet 1.3) and, in 13.4.3 [temp.arg.nontype] paragraph 2,

A template-argument for a non-type template-parameter shall be a converted constant expression (7.7 [expr.const]) of the type of the template-parameter.

This omission is particularly important for template parameters of class type with lvalue template parameter objects whose addresses can be examined during construction. See also issue 2450.

Suggested resolution:

To avoid address-based paradoxes, template arguments for a template parameter of class type C that are not of that type or a derived type are converted to C to produce an exemplar. No restrictions are imposed on the conversion from a template argument to a constructor parameter, since explicit and list-initialization may already be used to limit conversions in a similar fashion. Template arguments that are of such a type are used directly as the exemplar (potentially after a materialization conversion); the effect is as if the template parameter were of type const C& (except that temporaries are allowed). (In the latter case, we must impose some restrictions on glvalue template parameters to interpret them.) Each exemplar is used to copy-initialize the template parameter object to which it is (to be) template-argument-equivalent; the initialization is required to produce a template-argument-equivalent value. The multiple initializations of the template parameter object are (required to be) all equivalent and produce no side effects, so it is unobservable which happen.




2057. Template template arguments with default arguments

Section: 13.4.4  [temp.arg.template]     Status: drafting     Submitter: Jonathan Caves     Date: 2014-12-12

It is not clear how to handle an example like:

  template<typename T1, typename T2 = char> class A { };

  template<template<typename... T> class X> class S {
    X<int> x;
  };

  S<A> a;

Issue 184 dealt with a similar question but did so in the era before variadic templates. This usage should be permitted in modern C++.

Notes from the February, 2016 meeting:

CWG felt that this usage should be permitted, but only for template template parameters with a parameter pack.. Furthermore, if the template template parameter has a default argument followed by a parameter pack, the parameter's default argument would be used, followed by any remaining default arguments from the template template argument.




2398. Template template parameter matching and deduction

Section: 13.4.4  [temp.arg.template]     Status: drafting     Submitter: Jason Merrill     Date: 2016-12-03

Do the changes from P0522R0 regarding template template parameter matching apply to deduction? For example:

  template<class T, class U = T> class B { /* ... */ };
  template<template<class> class P, class T> void f(P<T>);

  int main()  {
    f(B<int>());       // OK?
    f(B<int,float>()); // ill-formed, T deduced to int and float
  }

In deduction we can determine that P is more specialized than B, then substitute B into P<T>, and then compare B<T,T> to B<int,int>. This will allow deduction to succeed, whereas comparing <T> to <int,int> without this substitution would fail. I suppose this is similar to deducing a type parameter, substituting it into the type of a non-type parameter, then deducing the value of the non-type parameter

Does this make sense? Do we need more wording?

Consider also this example;

  template<typename> struct match;

  template<template<typename> class t,typename T>
  struct match<t<T> > { typedef int type; };      // #1

  template<template<typename,typename> class t,typename T0,typename T1>
  struct match<t<T0,T1> > { typedef int type; };  // #2

  template<typename,typename = void> struct other { };
  typedef match<other<void,void> >::type type;

Before this change, partial specialization #1 was not a candidate; now it is, and neither partial specialization is at least as specialized as the other, so we get an ambiguity. It seems that the consistent way to address this would be to use other during partial ordering, so we'd be comparing

  template<typename T>
  void fn (match<other<T>>); // i.e. other<T,void>
  template<typename T0, typename T1>
  void fn (match<other<T0,T1>>);

So #1 is more specialized, whereas before this change we chose #2.




2037. Alias templates and template declaration matching

Section: 13.6  [temp.type]     Status: drafting     Submitter: Richard Smith     Date: 2014-11-06

For the following example,

  template<int N> struct A {};
  template<short N> using B = A<N>;
  template<int N> void f(B<N>) {} // #1
  template<int N> void f(A<N>) {} // #2

There is implementation variance as to whether there is one f or two. As with previously-discussed cases, these have different SFINAE effects, perhaps equivalent but not functionally equivalent. Should the argument to #1 be treated as something like A<(int)(short)N> and not just A<N>.

See also issues 1668 and 1979.




1730. Can a variable template have an unnamed type?

Section: 13.7  [temp.decls]     Status: drafting     Submitter: Larisse Voufo     Date: 2013-08-05

Is it permitted for a variable template to have an unnamed type?




1647. Type agreement of non-type template arguments in partial specializations

Section: 13.7.6  [temp.spec.partial]     Status: drafting     Submitter: John Spicer     Date: 2013-04-04

The Standard appears to be silent on whether the types of non-type template arguments in a partial specialization must be the same as those of the primary template or whether conversions are permitted. For example,

  template<char...> struct char_values {};
  template<int C1, char C3>
  struct char_values<C1, 12, C3> {
    static const unsigned value = 1;
  };
  int check0[char_values<1, 12, 3>::value == 1? 1 : -1];

The closest the current wording comes to dealing with this question is 13.7.6.1 [temp.spec.partial.general] bullet 9.1:

In this example, one might think of the first template argument in the partial specialization as (char)C1, which would violate the requirement, but that reasoning is tenuous.

It would be reasonable to require the types to match in cases like this. If this kind of usage is allowed it could get messy if the primary template were int... and the partial specialization had a parameter that was char because not all of the possible values from the primary template could be represented in the parameter of the partial specialization. A similar issue exists if the primary template takes signed char and the partial specialization takes unsigned int.

There is implementation variance in the treatment of this example.

(See also issues 1315, 2033, and 2127.)




2127. Partial specialization and nullptr

Section: 13.7.6  [temp.spec.partial]     Status: drafting     Submitter: Faisal Vali     Date: 2015-05-18

An example like the following would seem to be plausible:

  template<class T, T*> struct X { };
  // We want to partially specialize for all nullptrs...
  template<class T> struct X<T, nullptr> { ... }; // NOT OK

This is disallowed by the rule in bullet 9.2 of 13.7.6.1 [temp.spec.partial.general]:

(See also issues 1315, 1647, and 2033.)




2179. Required diagnostic for partial specialization after first use

Section: 13.7.6.1  [temp.spec.partial.general]     Status: drafting     Submitter: John Spicer     Date: 2015-10-12

According to 13.7.6.1 [temp.spec.partial.general] paragraph 1,

A partial specialization shall be declared before the first use of a class template specialization that would make use of the partial specialization as the result of an implicit or explicit instantiation in every translation unit in which such a use occurs; no diagnostic is required.

There are two problems with this wording. First, the “no diagnostic required” provision is presumably to avoid mandating cross-translation-unit analysis, but there is no reason not to require the diagnostic if the rule is violated within a single translation unit. Also, “would make use” is imprecise; it could be interpreted as applying only when the partial specialization would have been selected by a previous specialization, but it should also apply to cases where the partial specialization would have made a previous specialization ambiguous.

Making these two changes would guarantee that a diagnostic is issued for the following example:

   template <class T1, class T2> class A;
   template <class T> struct A<T, void> { void f(); };
   template <class T> void g(T) { A<char, void>().f(); }   // #1
   template<typename T> struct A<char, T> {};
   A<char, void> f;   // #2

It is unspecified whether the reference to A<char, void> at #1 is the “first use” or not. If so, A<char, void> is bound to the first partial specialization and, under the current wording, an implementation is not required to diagnose the ambiguity resulting from the second partial specialization. If #2 is the “first use,” it is clearly ambiguous and must result in a diagnostic. There is implementation divergence on the handling of this example that would be addressed by the suggested changes.




549. Non-deducible parameters in partial specializations

Section: 13.7.6.2  [temp.spec.partial.match]     Status: drafting     Submitter: Martin Sebor     Date: 18 November 2005

In the following example, the template parameter in the partial specialization is non-deducible:

    template <class T> struct A { typedef T U; };
    template <class T> struct C { };
    template <class T> struct C<typename A<T>::U> { };

Several compilers issue errors for this case, but there appears to be nothing in the Standard that would make this ill-formed; it simply seems that the partial specialization will never be matched, so the primary template will be used for all specializations. Should it be ill-formed?

(See also issue 1246.)

Notes from the April, 2006 meeting:

It was noted that there are similar issues for constructors and conversion operators with non-deducible parameters, and that they should probably be dealt with similarly.

Additional note, December, 2021:

The original issue, but not the *#8220;similar issues *#8221; pointed out in the 2006-04 note, was resolved by the changes for issue 1315 and paper P0127R2.




1755. Out-of-class partial specializations of member templates

Section: 13.7.6.4  [temp.spec.partial.member]     Status: drafting     Submitter: Richard Smith     Date: 2013-09-19

According to 13.7.6.4 [temp.spec.partial.member] paragraph 2,

If a member template of a class template is partially specialized, the member template partial specializations are member templates of the enclosing class template; if the enclosing class template is instantiated (13.9.2 [temp.inst], 13.9.3 [temp.explicit]), a declaration for every member template partial specialization is also instantiated as part of creating the members of the class template specialization.

Does this imply that only partial specializations of member templates that are declared before the enclosing class is instantiated are considered? For example, in

  template<typename A> struct X { template<typename B> struct Y; };
  template struct X<int>;
  template<typename A> template<typename B> struct X<A>::Y<B*> { int n; };
  int k = X<int>::Y<int*>().n;

is the last line valid? There is implementation variance on this point. Similarly, for an example like

  template<typename A> struct Outer {
   template<typename B, typename C> struct Inner;
  };
  Outer<int> outer;
  template<typename A> template<typename B>
    struct Outer<A>::Inner<typename A::error, B> {};

at what point, if at all, is the declaration of the partial specialization instantiated? Again, there is implementation variance in the treatment of this example.

Notes from the February, 2014 meeting:

CWG decided that partial specialization declarations should be instantiated only when needed to determine whether the partial specialization matches or not.

Additional note, November, 2014:

See also paper N4090.




1286. Equivalence of alias templates

Section: 13.7.8  [temp.alias]     Status: drafting     Submitter: Gabriel Dos Reis     Date: 2011-04-03

Issue 1244 was resolved by changing the example in 13.6 [temp.type] paragraph 1 from

  template<template<class> class TT> struct X { };
  template<class> struct Y { };
  template<class T> using Z = Y<T>;
  X<Y> y;
  X<Z> z;

to

  template<class T> struct X { };
  template<class> struct Y { };
  template<class T> using Z = Y<T>;
  X<Y<int> > y;
  X<Z<int> > z;

In fact, the original intent was that the example should have been correct as written; however, the normative wording to make it so was missing. The current wording of 13.7.8 [temp.alias] deals only with the equivalence of a specialization of an alias template with the type-id after substitution. Wording needs to be added specifying under what circumstances an alias template itself is equivalent to a class template.

Proposed resolution (September, 2012):

  1. Add the following as a new paragraph following 13.7.8 [temp.alias] paragraph 2:

  2. When the type-id in the declaration of alias template (call it A) consists of a simple-template-id in which the template-argument-list consists of a list of identifiers naming each template-parameter of A exactly once in the same order in which they appear in A's template-parameter-list, the alias template is equivalent to the template named in the simple-template-id (call it T) if A and T have the same number of template-parameters. [Footnote: This rule is transitive: if an alias template A is equivalent to another alias template B that is equivalent to a class template C, then A is also equivalent to C, and A and B are also equivalent to each other. —end footnote] [Example:

      template<typename T, U = T> struct A;
    
      template<typename V, typename W>
        using B = A<V, W>;                // equivalent to A
    
      template<typename V, typename W>
        using C = A<V>;                   // not equivalent to A:
                                          // not all parameters used
    
      template<typename V>
        using D = A<V>;                   // not equivalent to A:
                                          // different number of parameters
    
      template<typename V, typename W>
        using E = A<W, V>;                // not equivalent to A:
                                          // template-arguments in wrong order
    
      template<typename V, typename W = int>
        using F = A<V, W>;                // equivalent to A:
                                          // default arguments not considered
    
      template<typename V, typename W>
        using G = A<V, W>;                // equivalent to A and B
    
      template<typename V, typename W>
        using H = E<V, W>;                // equivalent to E
    
      template<typename V, typename W>
        using I = A<V, typename W::type>; // not equivalent to A:
                                          // argument not identifier
    
    

    end example]

  3. Change 13.6 [temp.type] paragraph 1 as follows:

  4. Two template-ids refer to the same class or function if

    [Example:

    ...declares x2 and x3 to be of the same type. Their type differs from the types of x1 and x4.

      template<class T template<class> class TT> struct X { };
      template<class> struct Y { };
      template<class T> using Z = Y<T>;
      X<Y<int> Y> y;
      X<Z<int> Z> z;
    

    declares y and z to be of the same type. —end example]

Additional note, November, 2014:

Concern has been expressed over the proposed resolution with regard to its handling of default template arguments that differ between the template and its alias, e.g.,

   template<typename T, typename U = int> struct A {};
   template<typename T, typename U = char> using B = A<T, U>;
   template<template<typename...> typename C> struct X { C<int> c; };

Notes from the May, 2015 meeting:

See also issue 1979, which CWG is suggesting to be resolved by defining a “simple” alias, one in which the SFINAE conditions are the same as the referenced template and that uses all template parameters.




1554. Access and alias templates

Section: 13.7.8  [temp.alias]     Status: drafting     Submitter: Jason Merrill     Date: 2012-09-17

The interaction of alias templates and access control is not clear from the current wording of 13.7.8 [temp.alias]. For example:

  template <class T> using foo = typename T::foo;

  class B {
    typedef int foo;
    friend struct C;
  };

  struct C {
    foo<B> f;    // Well-formed?
  };

Is the substitution of B::foo for foo<B> done in the context of the befriended class C, making the reference well-formed, or is the access determined independently of the context in which the alias template specialization appears?

If the answer to this question is that the access is determined independently from the context, care must be taken to ensure that an access failure is still considered to be “in the immediate context of the function type” (13.10.3 [temp.deduct] paragraph 8) so that it results in a deduction failure rather than a hard error.

Notes from the October, 2012 meeting:

The consensus of CWG was that instantiation (lookup and access) for alias templates should be as for other templates, in the definition context rather than in the context where they are used. They should still be expanded immediately, however.

Additional note (February, 2014):

A related problem is raised by the definition of std::enable_if_t (21.3.3 [meta.type.synop]):

  template <bool b, class T = void>
  using enable_if_t = typename enable_if<b,T>::type;

If b is false, there will be no type member. The intent is that such a substitution failure is to be considered as being “in the immediate context” where the alias template specialization is used, but the existing wording does not seem to accomplish that goal.

Additional note, November, 2014:

Concern has been expressed that the intent to analyze access in the context of the alias template definition is at odds with the fact that friendship cannot be granted to alias templates; if it could, the access violation in the original example could be avoided by making foo a friend of class B, but that is not possible.

Additional node, February, 2016:

The issue has been returned to "open" status to facilitate further discussion by CWG as to whether the direction in the October, 2012 note is still desirable.

Notes from the February, 2016 meeting:

CWG reaffirmed the direction described in the October, 2012 note above. With regard to the November, 2014 note regarding granting of friendship, it was observed that the same problem occurs with enumerators, which might refer to inaccessible names in the enumerator volue. The solution in both cases is to embed the declaration in a class and grant the class friendship. See issue 1844, dealing with the definition of “immediate context.”




1979. Alias template specialization in template member definition

Section: 13.7.8  [temp.alias]     Status: drafting     Submitter: Gabriel Dos Reis     Date: 2014-07-31

In an example like

  template<typename T> struct A {
    struct B {
      void f();
    };
  };

  template<typename T> using X = typename A<T>::B;

  template<typename T> void X<T>::f() { }       // #1

should #1 be considered a definition of A<T>::B::f()?

Analogy with alias-declarations would suggest that it should, but alias template specializations involve issues like SFINAE on unused template parameters (see issue 1558) and possibly other complications.

(See also issues 1980, 2021, 2025, and 2037.)

Notes from the May, 2015 meeting:

CWG felt that this kind of usage should be permitted only via a “simple” alias, in which the SFINAE is the same as the template to which it refers and all the template parameters are used. See also issue 1286.




1980. Equivalent but not functionally-equivalent redeclarations

Section: 13.7.8  [temp.alias]     Status: drafting     Submitter: Richard Smith     Date: 2014-08-04

In an example like

  template<typename T, typename U> using X = T;
  template<typename T> X<void, typename T::type> f();
  template<typename T> X<void, typename T::other> f();

it appears that the second declaration of f is a redeclaration of the first but distinguishable by SFINAE, i.e., equivalent but not functionally equivalent.

Notes from the November, 2014 meeting:

CWG felt that these two declarations should not be equivalent.




2236. When is an alias template specialization dependent?

Section: 13.7.8  [temp.alias]     Status: drafting     Submitter: Maxim Kartashev     Date: 2016-03-01

There is implementation divergence for this example:

  struct A { typedef int type; };
  template <typename T> using ALIAS = A;

  template <typename T> void foo()
  {
     ALIAS<T>::type t; // Is typename required here?
  }

  int main()
  {
    foo<A>();
  } 

See also issues 1558, 1979, and 2037.




2462. Problems with the omission of the typename keyword

Section: 13.8.1  [temp.res.general]     Status: drafting     Submitter: Mark Hall     Date: 2020-12-03

According to 13.8.2 [temp.local] paragraph 5,

A qualified-id is assumed to name a type if

There are two possible problems with this specification. First, consider an example like

   template<typename T> struct S {
     static void (*pfunc)(T::name);                               // Omitted typename okay because it is a
                                                                  // member-declaration
   };
   template<typename T> void (*S<T>::pfunc)(T::name) = nullptr;   // Omitted typename ill-formed because not a function
                                                                  // or function template declaration

Should bullet 5.2.4 be extended to include function pointer and member function pointer declarations, as well as function and function template declarations?

Second, given an example like

   template<typename T> struct Y {};
   template<typename T> struct S {
     Y<int(T::type)> m;  // Omitted typename okay because it is in a member-declaration?
  };

Should bullet 5.2.3 be restricted to parameter-declarations of the member being declared, rather than simply “in” such a member-declaration?

Notes from the December, 2020 teleconference:

The second issue was split off into issue 2468 to allow the resolutions to proceed independently.




2468. Omission of the typename keyword in a member template parameter list

Section: 13.8.1  [temp.res.general]     Status: drafting     Submitter: Mark Hall     Date: 2020-12-03

According to 13.8.2 [temp.local] paragraph 5,

A qualified-id is assumed to name a type if

This specification would appear to allow an example like:

   template<typename T> struct Y {};
   template<typename T> struct S {
     Y<int(T::type)> m;  // Omitted typename okay because it is in a member-declaration?
  };

The affected parameter-declarations should be only those of the member declarator, not in a member template's template parameter list.

(Note: this issue was spun off from issue 2462 to allow the resolutions to proceed independently.)




1390. Dependency of alias template specializations

Section: 13.8.3.2  [temp.dep.type]     Status: drafting     Submitter: Johannes Schaub     Date: 2011-09-04

According to 13.8.3.2 [temp.dep.type] paragraph 8, a type is dependent (among other things) if it is

This applies to alias template specializations, even if the resulting type does not depend on the template argument:

    struct B { typedef int type; };
    template<typename> using foo = B;
    template<typename T> void f() {
      foo<T>::type * x;  //error: typename required
    }

Is a change to the rules for cases like this warranted?

Notes from the October, 2012 meeting:

CWG agreed that no typename should be required in this case. In some ways, an alias template specialization is like the current instantiation and can be known at template definition time.




1524. Incompletely-defined class template base

Section: 13.8.3.2  [temp.dep.type]     Status: drafting     Submitter: Jason Merrill     Date: 2012-07-17

The correct handling of an example like the following is unclear:

  template<typename T> struct A {
    struct B: A { };
  };

A type used as a base must be complete (11.7 [class.derived] paragraph 2) . The fact that the base class in this example is the current instantiation could be interpreted as indicating that it should be available for lookup, and thus the normal rule should apply, as members declared after the nested class would not be visible.

On the other hand, 13.8.3 [temp.dep] paragraph 3 says,

In the definition of a class or class template, if a base class depends on a template-parameter, the base class scope is not examined during unqualified name lookup either at the point of definition of the class template or member or during an instantiation of the class template or member.

This wording refers not to a dependent type, which would permit lookup in the current instantiation, but simply to a type that “depends on a template-parameter,” and the current instantiation is such a type.

Implementations vary on the handling of this example.

(See also issue 1526 for another case related to the distinction between a “dependent type” and a “type that depends on a template-parameter.”)

Notes from the October, 2012 meeting:

CWG determined that the example should be ill-formed.




2074. Type-dependence of local class of function template

Section: 13.8.3.2  [temp.dep.type]     Status: drafting     Submitter: Richard Smith     Date: 2015-01-20

According to 13.8.3.2 [temp.dep.type] paragraph 9, a local class in a function template is dependent if and only if it contains a subobject of a dependent type. However, given an example like

  template<typename T> void f() {
    struct X {
      typedef int type;
  #ifdef DEPENDENT
      T x;
  #endif
    };
  X::type y;    // #1
  }
  void g() { f<int>(); }

there is implementation variance in the treatment of #1, but whether or not DEPENDENT is defined appears to make no difference.

In a related question, should a value-dependent alignas specifier cause a type to be dependent? Given

  template<int N> struct Y { typedef int type; };
  template<int N> void h() {
    struct alignas(N) X {};
    Y<alignof(X)>::type z;   // #2
  }
  void i() { h<4>(); }

Most/all implementations issue an error for a missing typename in #2.

Perhaps the right answer is that the types should be dependent but a member of the current instantiation, permitting name lookup without typename.

Additional notes (September, 2022):

At present, the term "current instantiation" is defined for class templates only, and thus does not apply to function templates.

Moreover, the resolution for this issue should also handle local enums, with particular attention to 9.7.2 [enum.udecl] paragraph 1:

The elaborated-enum-specifier shall not name a dependent type and...

This rule, without amendment, would disallow the following reasonable example if local enums were made dependent types:

template <class T>
void f() {
  enum class E { e1, e2 };
  using enum E;
}



2275. Type-dependence of function template

Section: 13.8.3.3  [temp.dep.expr]     Status: drafting     Submitter: Jason Merrill     Date: 2016-06-21

Consider:

  struct B { template <class T> void h(); };
  template <class T> struct A {
    template <class U> static U f(U);
    void g() {
     f(B()).h<int>(); // OK, f(B()) is non-type-dependent with type B.
    }
  }; 

A member template ought to be dependent only if it depends on template parameters of the current scope, but 13.8.3.3 [temp.dep.expr] paragraph 3 is silent on the matter.




2487. Type dependence of function-style cast to incomplete array type

Section: 13.8.3.3  [temp.dep.expr]     Status: drafting     Submitter: Richard Smith     Date: 2021-03-12

Consider:

  using T = int[];
  using U = int[2];
  template<auto M, int ...N> void f() {
    auto &&arr1 = T(N...);
    auto &&arr2 = T{N...};
    auto &&arr3 = U(M, M);
    auto &&arr4 = U{M, M};
  };

I think here T(N...) is not type-dependent, per 13.8.3.3 [temp.dep.expr] paragraph 3, but should be. (I think T{N...} is type-dependent.) Conversely, I think U{M, M} is type-dependent, per 13.8.3.3 [temp.dep.expr] paragraph 6, but should not be. (U(M, M) is not type-dependent.)

I think we should say that

are type-dependent if the type specifier names a dependent type, or if it names an array of unknown bound and the braced-init-list or expression-list is type-dependent.

(I think we could be a little more precise than that in the case where there is no top-level pack expansion: T{M, M} needs to be type-dependent for a general array of unknown bound T due to brace elision, but not in the case where the array element type is a scalar type. And T(M, M) does not need to be type-dependent because direct aggregate initialization can't perform brace elision. But I think the simpler rule is probably good enough.)

Notes from the August, 2021 teleconference:

CWG agreed with the suggested change. There was some support for the “more precise” approach mentioned in the description.




2090. Dependency via non-dependent base class

Section: 13.8.3.5  [temp.dep.temp]     Status: drafting     Submitter: Maxim Kartashev     Date: 2015-02-27

According to 13.8.3.5 [temp.dep.temp] paragraph 3,

a non-type template-argument is dependent if the corresponding non-type template-parameter is of reference or pointer type and the template-argument designates or points to a member of the current instantiation or a member of a dependent type.

Members of non-dependent base classes are members of the current instantiation, but using one as a non-type template argument should not be considered dependent.




2. How can dependent names be used in member declarations that appear outside of the class template definition?

Section: 13.8.4  [temp.dep.res]     Status: drafting     Submitter: unknown     Date: unknown
    template <class T> class Foo {

       public:
       typedef int Bar;
       Bar f();
    };
    template <class T> typename Foo<T>::Bar Foo<T>::f() { return 1;}
                       --------------------
In the class template definition, the declaration of the member function is interpreted as:
   int Foo<T>::f();
In the definition of the member function that appears outside of the class template, the return type is not known until the member function is instantiated. Must the return type of the member function be known when this out-of-line definition is seen (in which case the definition above is ill-formed)? Or is it OK to wait until the member function is instantiated to see if the type of the return type matches the return type in the class template definition (in which case the definition above is well-formed)?

Suggested resolution: (John Spicer)

My opinion (which I think matches several posted on the reflector recently) is that the out-of-class definition must match the declaration in the template. In your example they do match, so it is well formed.

I've added some additional cases that illustrate cases that I think either are allowed or should be allowed, and some cases that I don't think are allowed.

    template <class T> class A { typedef int X; };


    template <class T> class Foo {
     public:
       typedef int Bar;
       typedef typename A<T>::X X;
       Bar f();
       Bar g1();
       int g2();
       X h();
       X i();
       int j();
     };

     // Declarations that are okay
     template <class T> typename Foo<T>::Bar Foo<T>::f()
                                                     { return 1;}
     template <class T> typename Foo<T>::Bar Foo<T>::g1()
                                                     { return 1;}
     template <class T> int Foo<T>::g2() { return 1;}
     template <class T> typename Foo<T>::X Foo<T>::h() { return 1;}

     // Declarations that are not okay
     template <class T> int Foo<T>::i() { return 1;}
     template <class T> typename Foo<T>::X Foo<T>::j() { return 1;}
In general, if you can match the declarations up using only information from the template, then the declaration is valid.

Declarations like Foo::i and Foo::j are invalid because for a given instance of A<T>, A<T>::X may not actually be int if the class is specialized.

This is not a problem for Foo::g1 and Foo::g2 because for any instance of Foo<T> that is generated from the template you know that Bar will always be int. If an instance of Foo is specialized, the template member definitions are not used so it doesn't matter whether a specialization defines Bar as int or not.




287. Order dependencies in template instantiation

Section: 13.8.4.1  [temp.point]     Status: drafting     Submitter: Martin Sebor     Date: 17 May 2001

Implementations differ in their treatment of the following code:

    template <class T>
    struct A {
	typename T::X x;
    };

    template <class T>
    struct B {
	typedef T* X;
	A<B> a;
    };

    int main ()
    {
	B<int> b;
    }

Some implementations accept it. At least one rejects it because the instantiation of A<B<int> > requires that B<int> be complete, and it is not at the point at which A<B<int> > is being instantiated.

Erwin Unruh:

In my view the programm is ill-formed. My reasoning:

So each class needs the other to be complete.

The problem can be seen much easier if you replace the typedef with

    typedef T (*X) [sizeof(B::a)];

Now you have a true recursion. The compiler cannot easily distinguish between a true recursion and a potential recursion.

John Spicer:

Using a class to form a qualified name does not require the class to be complete, it only requires that the named member already have been declared. In other words, this kind of usage is permitted:

    class A {
        typedef int B;
        A::B ab;
    };

In the same way, once B has been declared in A, it is also visible to any template that uses A through a template parameter.

The standard could be more clear in this regard, but there are two notes that make this point. Both 6.5.5.2 [class.qual] and _N4567_.5.1.1 [expr.prim.general] paragraph 7 contain a note that says "a class member can be referred to using a qualified-id at any point in its potential scope (6.4.7 [basic.scope.class])." A member's potential scope begins at its point of declaration.

In other words, a class has three states: incomplete, being completed, and complete. The standard permits a qualified name to be used once a name has been declared. The quotation of the notes about the potential scope was intended to support that.

So, in the original example, class A does not require the type of T to be complete, only that it have already declared a member X.

Bill Gibbons:

The template and non-template cases are different. In the non-template case the order in which the members become declared is clear. In the template case the members of the instantiation are conceptually all created at the same time. The standard does not say anything about trying to mimic the non-template case during the instantiation of a class template.

Mike Miller:

I think the relevant specification is 13.8.4.1 [temp.point] paragraph 3, dealing with the point of instantiation:

For a class template specialization... if the specialization is implicitly instantiated because it is referenced from within another template specialization, if the context from which the specialization is referenced depends on a template parameter, and if the specialization is not instantiated previous to the instantiation of the enclosing template, the point of instantiation is immediately before the point of instantiation of the enclosing template. Otherwise, the point of instantiation for such a specialization immediately precedes the namespace scope declaration or definition that refers to the specialization.

That means that the point of instantiation of A<B<int> > is before that of B<int>, not in the middle of B<int> after the declaration of B::X, and consequently a reference to B<int>::X from A<B<int> > is ill-formed.

To put it another way, I believe John's approach requires that there be an instantiation stack, with the results of partially-instantiated templates on the stack being available to instantiations above them. I don't think the Standard mandates that approach; as far as I can see, simply determining the implicit instantiations that need to be done, rewriting the definitions at their respective points of instantiation with parameters substituted (with appropriate "forward declarations" to allow for non-instantiating references), and compiling the result normally should be an acceptable implementation technique as well. That is, the implicit instantiation of the example (using, e.g., B_int to represent the generated name of the B<int> specialization) could be something like

        struct B_int;

        struct A_B_int {
            B_int::X x;    // error, incomplete type
        };

        struct B_int {
            typedef int* X;
            A_B_int a;
        };

Notes from 10/01 meeting:

This was discussed at length. The consensus was that the template case should be treated the same as the non-template class case it terms of the order in which members get declared/defined and classes get completed.

Proposed resolution:

In 13.8.4.1 [temp.point] paragraph 3 change:

the point of instantiation is immediately before the point of instantiation of the enclosing template. Otherwise, the point of instantiation for such a specialization immediately precedes the namespace scope declaration or definition that refers to the specialization.

To:

the point of instantiation is the same as the point of instantiation of the enclosing template. Otherwise, the point of instantiation for such a specialization immediately precedes the nearest enclosing declaration. [Note: The point of instantiation is still at namespace scope but any declarations preceding the point of instantiation, even if not at namespace scope, are considered to have been seen.]

Add following paragraph 3:

If an implicitly instantiated class template specialization, class member specialization, or specialization of a class template references a class, class template specialization, class member specialization, or specialization of a class template containing a specialization reference that directly or indirectly caused the instantiation, the requirements of completeness and ordering of the class reference are applied in the context of the specialization reference.

and the following example

  template <class T> struct A {
          typename T::X x;
  };

  struct B {
          typedef int X;
          A<B> a;
  };

  template <class T> struct C {
          typedef T* X;
          A<C> a;
  };

  int main ()
  {
          C<int> c;
  }

Notes from the October 2002 meeting:

This needs work. Moved back to drafting status.

See also issues 595 and 1330.




1845. Point of instantiation of a variable template specialization

Section: 13.8.4.1  [temp.point]     Status: drafting     Submitter: Richard Smith     Date: 2014-01-28

The current wording of 13.8.4.1 [temp.point] does not define the point of instantiation of a variable template specialization. Presumably replacing the references to “static data member of a class template” with “variable template” in paragraphs 1 and 8 would be sufficient.

Additional note, July, 2017:

It has also been observed that there is no definition of the point of instantiation for an alias template. It is not clear that there is a need for normative wording for the point of instantiation of an alias template, but if not, a note explaining its absence would be helpful.




2245. Point of instantiation of incomplete class template

Section: 13.8.4.1  [temp.point]     Status: drafting     Submitter: Richard Smith     Date: 2016-03-08

Consider:

  template<typename T> struct X;

  extern X<int> *p;
  void *q = +p; // #1, complete type affects semantics via ADL

  template<typename T> struct X {};
  X<int> x; // #2, ill-formed, X<int> is incomplete

According to the wording of issue 212, this program is ill-formed, because the single point of instantiation for X<int> is at #1, thus X<int> is an incomplete type even at #2 after the primary template has been completed.

Notes from the December, 2016 teleconference:

The consensus was that references to specializations before the template definition is seen are not points of instantiation.




2497. Points of instantiation for constexpr function templates

Section: 13.8.4.1  [temp.point]     Status: drafting     Submitter: Richard Smith     Date: 2019-07-20

Consider:

  template<typename T> constexpr T f();
  constexpr int g() { return f<int>(); } // #1
  template<typename T> constexpr T f() { return 123; }
  int k[g()];
  // #2

There are two points of instantiation for f<int>. At #1, the template isn't defined, so it cannot be instantiated there. At #2, it's too late, as the definition was needed when parsing the type of k.

Should we also treat the point of definition of (at least) a constexpr function template as a point of instantiation for all specializations that have a point of instantiation before that point? Note the possible interaction of such a resolution with 13.8.4.1 [temp.point] paragraph 7:

If two different points of instantiation give a template specialization different meanings according to the one-definition rule (6.3 [basic.def.odr]), the program is ill-formed, no diagnostic required.

Notes from the November, 2021 teleconference:

Another possibility for a point of instantiation, other than the definition of the template, would be the point at which the function is called. Similar questions have been raised regarding the points at which variables are initialized (issue 2186) and constexpr functions are defined (issue 2166).




2202. When does default argument instantiation occur?

Section: 13.9.2  [temp.inst]     Status: drafting     Submitter: Richard Smith     Date: 2015-11-19

According to 13.9.2 [temp.inst] paragraph 11,

If a function template f is called in a way that requires a default argument to be used, the dependent names are looked up, the semantics constraints are checked, and the instantiation of any template used in the default argument is done as if the default argument had been an initializer used in a function template specialization with the same scope, the same template parameters and the same access as that of the function template f used at that point, except that the scope in which a closure type is declared (7.5.5.2 [expr.prim.lambda.closure]) — and therefore its associated namespaces — remain as determined from the context of the definition for the default argument. This analysis is called default argument instantiation. The instantiated default argument is then used as the argument of f.

Some details are not clear from this description. For example, given

  #include <type_traits>
  template<class T> struct Foo { Foo(T = nullptr) {} };
  bool b = std::is_constructible<Foo<int>>::value;
  int main() {}

does “used” mean odr-used or used in any way? Is a failure of default argument instantiation in the immediate context of the call or is a failure a hard error? And does it apply only to function templates, as it says, or should it apply to member functions of class templates? There is implementation divergence on these questions.

Notes from the March, 2018 meeting:

CWG felt that such errors should be substitution failures, not hard errors.




2222. Additional contexts where instantiation is not required

Section: 13.9.2  [temp.inst]     Status: drafting     Submitter: CWG     Date: 2016-01-11

According to 13.9.2 [temp.inst] paragraph 6,

If the function selected by overload resolution (12.2 [over.match]) can be determined without instantiating a class template definition, it is unspecified whether that instantiation actually takes place.

There are other contexts in which a smart implementation could presumably avoid instantiations, such as when doing argument-dependent lookup involving a class template specialization when the template definition contains no friend declarations or checking base/derived relationships involving incomplete class template definitions. It would be helpful to enumerate such contexts.




2263. Default argument instantiation for friends

Section: 13.9.2  [temp.inst]     Status: drafting     Submitter: Hubert Tong     Date: 2016-05-04

The instantiation of default arguments for friends defined in a templated entity is not covered by 13.7.1 [temp.decls.general] paragraph 3 or 13.9.2 [temp.inst] paragraph 2. Consider:

  template <typename T>
  struct A {
    friend void foo(A &&, int = T::happy) { }
  };

  int main(void) { foo(A<int>(), 0); }

There is implementation divergence in the treatment of this example.

Notes from the December, 2016 teleconference:

This issue should be resolved by the resolution of issue 2174.




2265. Delayed pack expansion and member redeclarations

Section: 13.9.2  [temp.inst]     Status: drafting     Submitter: Hubert Tong     Date: 2016-05-11

It is not clear how to handle parameter packs that are expanded during instantiation in parallel with those that are not yet concrete. In particular, does the following example require a diagnostic?

  template<typename ...T> struct Tuple;
  template<class T, class U> struct Outer;
  template<class ...T, class ...U>
  struct Outer<Tuple<T ...>, Tuple<U ...> > {
    template<class X, class Y> struct Inner;
    template<class ...Y> struct Inner<Tuple<T, Y> ...> { };
    template<class ...Y> struct Inner<Tuple<U, Y> ...> { };
  };
  Outer<Tuple<int, void>, Tuple<int, void> > outer;

Notes from the March, 2018 meeting:

CWG felt that ill-formed, no diagnostic required was the correct approach.




2596. Instantiation of constrained non-template friends

Section: 13.9.2  [temp.inst]     Status: drafting     Submitter: David Friberg     Date: 2022-06-03

Consider:

  struct Base {};

  template<int N>
  struct S : public Base {
    friend int foo(Base&) requires (N == 1) { return 1; }
    friend int foo(Base&) requires (N == 2) { return 3; }
  };

  int main() {
    S<1> s1{};
    S<2> s2{};  // #1
  }

The current wording does not seem to cover what happens for this case. In particular, 13.9.2 [temp.inst] paragraph 17 does not cover constrained non-template friends.

See also the Itanium ABI issue 24.

Suggested resolution:

  1. Change in 13.7.5 [temp.friend] paragraph 9 as follows:

    A non-template friend declaration with a requires-clause shall be a definition. A friend function template with a constraint that depends on a template parameter from an enclosing template shall be a definition. Such a constrained friend function or function template declaration does not declare the same function or function template as a declaration in inhabiting any other scope.
  2. Change in 13.9.2 [temp.inst] paragraph 17 as follows:

    The type-constraints and requires-clause of a template specialization or member templated function are not instantiated along with the specialization or function itself, even for a member function of a local class; substitution into the atomic constraints formed from them is instead performed as specified in 13.5.3 [temp.constr.decl] and 13.5.2.3 [temp.constr.atomic] when determining whether the constraints are satisfied or as specified in 13.5.3 [temp.constr.decl] when comparing declarations.

    [ Note 7: ... ]

    [ Example 10: ... ]

    [ Example:

      struct Base {};
    
      template<int N>
      struct S : Base {
        friend int foo(Base&) requires (N == 1) { return 1; }  // #1
        friend int foo(Base&) requires (N == 2) { return 3; }  // #2
      };
      S<1> s1;
      S<2> s2;          // OK, no conflict between #1 and #2
      int x = foo(s1);  // OK, selects #1
      int y = foo(s2);  // OK, selects #2
    

    -- end example ]

    [ Example 11: ... ]

CWG 2022-11-10

The friend definitions should conflict with friend definitions from other instantiations of the same class template, consistent with how non-constrained friends would work. Note that the enclosing dependent class type does not appear in the friend function's signature, which is unusual.




1665. Declaration matching in explicit instantiations

Section: 13.9.3  [temp.explicit]     Status: drafting     Submitter: Richard Smith     Date: 2013-04-19

Consider a case like

  struct X {
    template<typename T> void f(T);
    void f(int);
  };
  template void X::f(int);

or

  template<typename T> void f(T) {}
  void f(int);
  template void f(int);

Presumably in both these cases the explicit instantiation should refer to the template and not to the non-template; however, 13.7.3 [temp.mem] paragraph 2 says,

A normal (non-template) member function with a given name and type and a member function template of the same name, which could be used to generate a specialization of the same type, can both be declared in a class. When both exist, a use of that name and type refers to the non-template member unless an explicit template argument list is supplied.

This would appear to give the wrong answer for the first example. It's not clearly stated, but consistency would suggest a similar wrong answer for the second. Presumably a statement is needed somewhere that an explicit instantiation directive applies to a template and not a non-template function if both are visible.

Additional note, January, 2014:

A related example has been raised:

  template<typename T> class Matrix {
  public:
    Matrix(){}
    Matrix(const Matrix&){}
    template<typename U>
      Matrix(const Matrix<U>&);
  };

  template Matrix<int>::Matrix(const Matrix&);

  Matrix<int> m;
  Matrix<int> mm(m);

If the explicit instantiation directive applies to the constructor template, there is no way to explicitly instantiate the copy constructor.




2421. Explicit instantiation of constrained member functions

Section: 13.9.3  [temp.explicit]     Status: drafting     Submitter: Casey Carter     Date: 2019-07-16

An explicit instantiation of a class template specialization also explicitly instantiates member functions of that class template specialization whose constraints are satisfied, even those that are not callable because a more-constrained overload exists which would always be selected by overload resolution. Ideally, we would not explicitly instantiate definitions of such uncallable functions.

Notes from the August, 2020 teleconference:

CWG felt that the concept of “eligible” might form a basis for the resolution of this issue.




2501. Explicit instantiation and trailing requires-clauses

Section: 13.9.3  [temp.explicit]     Status: drafting     Submitter: Davis Herring     Date: 2021-08-09

CWG determined that issue 2488 was not a defect. However, the discussion uncovered an issue regarding the handling of an explicit instantiation of a class template containing such members. According to 13.9.3 [temp.explicit] paragraph 10,

An explicit instantiation that names a class template specialization is also an explicit instantiation of the same kind (declaration or definition) of each of its direct non-template members that has not been previously explicitly specialized in the translation unit containing the explicit instantiation, provided that the associated constraints, if any, of that member are satisfied by the template arguments of the explicit instantiation (13.5.3 [temp.constr.decl], 13.5.2 [temp.constr.constr]), except as described below.

Paragraph 12 says,

An explicit instantiation of a prospective destructor (11.4.7 [class.dtor]) shall correspond to the selected destructor of the class.

Perhaps the virtual and constrained members could be handled in an analogous fashion.

Notes from the November, 2021 teleconference:

Issue 2488 is being reopened due to subsequent comments.

CWG 2022-11-10

For each explicit instantiation, there shall be exactly one member whose constraints are more specialized than any other member with the same signature. Use the "address of function" model to determine this member.




529. Use of template<> with “explicitly-specialized” class templates

Section: 13.9.4  [temp.expl.spec]     Status: drafting     Submitter: James Widman     Date: 16 August 2005

Paragraph 17 of 13.9.4 [temp.expl.spec] says,

A member or a member template may be nested within many enclosing class templates. In an explicit specialization for such a member, the member declaration shall be preceded by a template<> for each enclosing class template that is explicitly specialized.

This is curious, because paragraph 3 only allows explicit specialization of members of implicitly-instantiated class specializations, not explicit specializations. Furthermore, paragraph 4 says,

Definitions of members of an explicitly specialized class are defined in the same manner as members of normal classes, and not using the explicit specialization syntax.

Paragraph 18 provides a clue for resolving the apparent contradiction:

In an explicit specialization declaration for a member of a class template or a member template that appears in namespace scope, the member template and some of its enclosing class templates may remain unspecialized, except that the declaration shall not explicitly specialize a class member template if its enclosing class templates are not explicitly specialized as well. In such explicit specialization declaration, the keyword template followed by a template-parameter-list shall be provided instead of the template<> preceding the explicit specialization declaration of the member.

It appears from this and the following example that the phrase “explicitly specialized” in paragraphs 17 and 18, when referring to enclosing class templates, does not mean that explicit specializations have been declared for them but that their names in the qualified-id are followed by template argument lists. This terminology is confusing and should be changed.

Proposed resolution (October, 2005):

  1. Change 13.9.4 [temp.expl.spec] paragraph 17 as indicated:

  2. A member or a member template may be nested within many enclosing class templates. In an explicit specialization for such a member, the member declaration shall be preceded by a template<> for each enclosing class template that is explicitly specialized specialization. [Example:...
  3. Change 13.9.4 [temp.expl.spec] paragraph 18 as indicated:

  4. In an explicit specialization declaration for a member of a class template or a member template that appears in namespace scope, the member template and some of its enclosing class templates may remain unspecialized, except that the declaration shall not explicitly specialize a class member template if its enclosing class templates are not explicitly specialized as well that is, the template-id naming the template may be composed of template parameter names rather than template-arguments. In For each unspecialized template in such an explicit specialization declaration, the keyword template followed by a template-parameter-list shall be provided instead of the template<> preceding the explicit specialization declaration of the member. The types of the template-parameters in the template-parameter-list shall be the same as those specified in the primary template definition. In such declarations, an unspecialized template-id shall not precede the name of a template specialization in the qualified-id naming the member. [Example:...

Notes from the April, 2006 meeting:

The revised wording describing “unspecialized” templates needs more work to ensure that the parameter names in the template-id are in the correct order; the distinction between template arguments and parameters is also probably not clear enough. It might be better to replace this paragraph completely and avoid the “unspecialized” wording altogether.

Proposed resolution (February, 2010):

  1. Change 13.9.4 [temp.expl.spec] paragraph 17 as follows:

  2. A member or a member template may be nested within many enclosing class templates. In an explicit specialization for such a member, the member declaration shall be preceded by a template<> for each enclosing class template that is explicitly specialized specialization. [Example:...
  3. Change 13.9.4 [temp.expl.spec] paragraph 18 as follows:

  4. In an explicit specialization declaration for a member of a class template or a member template that appears in namespace scope, the member template and some of its enclosing class templates may remain unspecialized, except that the declaration shall not explicitly specialize a class member template if its enclosing class templates are not explicitly specialized as well. In such explicit specialization declaration, the keyword template followed by a template-parameter-list shall be provided instead of the template<> preceding the explicit specialization declaration of the member. The types of the template-parameters in the template-parameter-list shall be the same as those specified in the primary template definition. that is, the corresponding template prefix may specify a template-parameter-list instead of template<> and the template-id naming the template be written using those template-parameters as template-arguments. In such a declaration, the number, kinds, and types of the template-parameters shall be the same as those specified in the primary template definition, and the template-parameters shall be named in the template-id in the same order that they appear in the template-parameter-list. An unspecialized template-id shall not precede the name of a template specialization in the qualified-id naming the member. [Example:...



1840. Non-deleted explicit specialization of deleted function template

Section: 13.9.4  [temp.expl.spec]     Status: drafting     Submitter: Richard Smith     Date: 2014-01-19

The resolution of issue 941 permits a non-deleted explicit specialization of a deleted function template. For example:

  template<typename T> void f() = delete;
  decltype(f<int>()) *p;
  template<> void f<int>();

However, the existing normative wording is not adequate to handle this usage. For one thing, =delete is formally, at least, a function definition, and an implementation is not permitted to instantiate a function definition unless it is used; presumably, then, an implementation could not reject the decltype above as a reference to a deleted specialization. Furthermore, there should be a requirement that a non-deleted explicit specialization of a deleted function template must precede any reference to that specialization. (I.e., the example should be ill-formed as written but well-formed if the last two lines were interchanged.)




1993. Use of template<> defining member of explicit specialization

Section: 13.9.4  [temp.expl.spec]     Status: drafting     Submitter: Richard Smith     Date: 2014-08-31

Issue 531 surveyed existing practice at the time and determined that the most common syntax for defining a member of an explicit specialization used the template<> prefix. This approach, however, does not seem consistent, since such a definition is not itself an explicit specialization.




2409. Explicit specializations of constexpr static data members

Section: 13.9.4  [temp.expl.spec]     Status: drafting     Submitter: Mike Miller     Date: 2019-04-29

The status of an example like the following is not clear:

  struct S {
    template <int N> static constexpr inline int m = N;
  };
  template <> constexpr inline int S::m<5>;

Some implementations accept this, apparently on the basis of allowing and ignoring a redeclaration of a constexpr static data member outside its class, although there is implementation divergence. Most or all implementations, however, diagnose an attempt to use such a specialization in a constant context.

Should it be required to have a definition of the explicit specialization in order to declare it outside the class in such cases?

In addition, most or all implementations accept a version of the example in which the explicit specialization contains an initializer, including allowing its use in constant contexts:

  template <> constexpr inline int S::m<5> = 2;

This would seem to be disallowed both by 11.4.9.3 [class.static.data] paragraph 3,

An inline static data member may be defined in the class definition and may specify a brace-or-equal-initializer. If the member is declared with the constexpr specifier, it may be redeclared in namespace scope with no initializer (this usage is deprecated; see _N4778_.D.4 [depr.static_constexpr]).

which prohibits an initializer, and 13.9.4 [temp.expl.spec] paragraph 2,

An explicit specialization may be declared in any scope in which the corresponding primary template may be defined (_N4868_.9.8.2.3 [namespace.memdef], 11.4 [class.mem], 13.7.3 [temp.mem]).

since the definition of a constexpr static data member is inside the class.

Notes from the May, 2019 teleconference:

These examples should behave in the same way as if the class were templated: instantiate the declaration and the definition of the static data member separately. The first example should be ill-formed, because the explicit specializaation does not have an initializer.




2055. Explicitly-specified non-deduced parameter packs

Section: 13.10.2  [temp.arg.explicit]     Status: drafting     Submitter: Jonathan Caves     Date: 2014-12-09

According to 13.10.2 [temp.arg.explicit] paragraph 3,

Trailing template arguments that can be deduced (13.10.3 [temp.deduct]) or obtained from default template-arguments may be omitted from the list of explicit template-arguments. A trailing template parameter pack (13.7.4 [temp.variadic]) not otherwise deduced will be deduced to an empty sequence of template arguments. If all of the template arguments can be deduced, they may all be omitted; in this case, the empty template argument list <> itself may also be omitted. In contexts where deduction is done and fails, or in contexts where deduction is not done, if a template argument list is specified and it, along with any default template arguments, identifies a single function template specialization, then the template-id is an lvalue for the function template specialization.

It is not clear that this permits an example like:

  template<typename... T> void f(typename T::type...)   {
  }

  int main() {
    f<>();
  }

See also issue 2105.




1172. “instantiation-dependent” constructs

Section: 13.10.3  [temp.deduct]     Status: drafting     Submitter: Adamczyk     Date: 2010-08-05

There are certain constructs that are not covered by the existing categories of “type dependent” and “value dependent.” For example, the expression sizeof(sizeof(T())) is neither type-dependent nor value-dependent, but its validity depends on whether T can be value-constructed. We should be able to overload on such characteristics and select via deduction failure, but we need a term like “instantiation-dependent” to describe these cases in the Standard. The phrase “expression involving a template parameter” seems to come pretty close to capturing this idea.

Notes from the November, 2010 meeting:

The CWG favored extending the concepts of “type-dependent” and “value-dependent” to cover these additional cases, rather than adding a new concept.

Notes from the March, 2011 meeting:

The CWG reconsidered the direction from the November, 2010 meeting, as it would make more constructs dependent, thus requiring more template and typename keywords, resulting in worse error messages, etc.

Notes from the August, 2011 meeting:

The following example (from issue 1273) was deemed relevant for this issue:

    template <class T> struct C;

    class A {
       int i;
       friend struct C<int>;
    } a;

    class B {
       int i;
       friend struct C<float>;
    } b;

    template <class T>
    struct C {
       template <class U> decltype (a.i) f() { } // #1
       template <class U> decltype (b.i) f() { } // #2
    };

    int main() {
       C<int>().f<int>();     // calls #1
       C<float>().f<float>(); // calls #2
    }



1322. Function parameter type decay in templates

Section: 13.10.3  [temp.deduct]     Status: drafting     Submitter: Jason Merrill     Date: 2011-05-19

The discussion of issue 1001 seemed to have settled on the approach of doing the 9.3.4.6 [dcl.fct] transformations immediately to the function template declaration, so that the original form need not be remembered. However, the example in 13.10.3 [temp.deduct] paragraph 8 suggests otherwise:

  template <class T> int f(T[5]);
  int I = f<int>(0);
  int j = f<void>(0); // invalid array

One way that might be addressed would be to separate the concepts of the type of the template that participates in overload resolution and function matching from the type of the template that is the source for template argument substitution. (See also the example in paragraph 3 of the same section.)

Notes, January, 2012:




1582. Template default arguments and deduction failure

Section: 13.10.3  [temp.deduct]     Status: drafting     Submitter: John Spicer     Date: 2012-10-31

According to 13.10.3 [temp.deduct] paragraph 5,

The resulting substituted and adjusted function type is used as the type of the function template for template argument deduction. If a template argument has not been deduced and its corresponding template parameter has a default argument, the template argument is determined by substituting the template arguments determined for preceding template parameters into the default argument. If the substitution results in an invalid type, as described above, type deduction fails.

This leaves the impression that default arguments are used after deduction failure leaves an argument undeduced. For example,

  template<typename T> struct Wrapper;
  template<typename T = int> void f(Wrapper<T>*);
  void g() {
    f(0);
  }

Deduction fails for T, so presumably int is used. However, some implementations reject this code. It appears that the intent would be better expressed as something like

...If a template argument is used only in a non-deduced context and its corresponding template parameter has a default argument...

Rationale (November, 2013):

CWG felt that this issue should be considered by EWG in a broader context before being resolved.

Additional note, April, 2015:

EWG has requested that CWG resolve this issue along the lines discussed above.

Notes from the May, 2015 meeting:

CWG agreed that a default template argument should only be used if the parameter is not used in a deducible context. See also issue 2092.




1513. initializer_list deduction failure

Section: 13.10.3.2  [temp.deduct.call]     Status: drafting     Submitter: Steve Adamczyk     Date: 2012-06-28

According to 13.10.3.2 [temp.deduct.call] paragraph 1,

If removing references and cv-qualifiers from P gives std::initializer_list<P'> for some P' and the argument is an initializer list (9.4.5 [dcl.init.list]), then deduction is performed instead for each element of the initializer list, taking P' as a function template parameter type and the initializer element as its argument. Otherwise, an initializer list argument causes the parameter to be considered a non-deduced context (13.10.3.6 [temp.deduct.type]).

It is not entirely clear whether the deduction for an initializer list meeting a std::initializer_list<T> is a recursive subcase, or part of the primary deduction. A relevant question is: if the deduction on that part fails, does the entire deduction fail, or is the parameter to be considered non-deduced?

See also issue 2326.

Notes from the October, 2012 meeting:

CWG determined that the entire deduction fails in this case.




1584. Deducing function types from cv-qualified types

Section: 13.10.3.2  [temp.deduct.call]     Status: drafting     Submitter: Daniel Krügler     Date: 2012-11-04

It is not clear whether the following is well-formed or not:

  void foo(){}

  template<class T>
  void deduce(const T*) { }

  int main() {
    deduce(foo);
  }

Implementations vary in their treatment of this example.

Proposed resolution (April, 2013):

Change 13.10.3.6 [temp.deduct.type] paragraph 18 as follows:

A template-argument can be deduced from a function, pointer to function, or pointer to member function type. [Note: cv-qualification of a deduced function type is ignored; see 9.3.4.6 [dcl.fct]. —end note] [Example:

  template<class T> void f(void(*)(T,int));
  template<class T> void f2(const T*);
  template<class T> void foo(T,int);
  void g(int,int);
  void g(char,int);
  void g2();

  void h(int,int,int);
  void h(char,int);
  int m() {
    f(&g);     // error: ambiguous
    f(&h);     // OK: void h(char,int) is a unique match
    f(&foo);   // error: type deduction fails because foo is a template
    f2(g2);    // OK: cv-qualification of deduced function type ignored
  }

end example]

Additional note, November, 2014:

Concern was expressed regarding the proposed resolution over its treatment of an example like the following:

  template<typename T> struct tuple_size {};
  template<typename T> struct tuple_size<T const>: tuple_size<T> {};

  tuple_size<void()> t;

In this case T const is always considered to be more specialized for void(), leading to infinite self-derivation.

The issue has been returned to "open" status for further consideration.

Notes from the May, 2015 meeting:

The consensus of CWG was that the cv-qualification of the argument and parameter must match, so the original example should be rejected.




1486. Base-derived conversion in member pointer deduction

Section: 13.10.3.3  [temp.deduct.funcaddr]     Status: drafting     Submitter: John Spicer     Date: 2012-03-26

The rules for deducing template arguments when taking the address of a function template in 13.10.3.3 [temp.deduct.funcaddr] do not appear to allow for a base-to-derived conversion in a case like:

  struct Base {
    template<class U> void f(U);
  };

  struct Derived : Base { };

  int main() {
    void (Derived::*pmf)(int) = &Derived::f;
  }

Most implementations appear to allow this adjustment, however.




1610. Cv-qualification in deduction of reference to array

Section: 13.10.3.5  [temp.deduct.partial]     Status: drafting     Submitter: Richard Smith     Date: 2013-01-28

Given

   template<class C> void foo(const C* val) {}
   template<int N> void foo(const char (&t)[N]) {}

it is intuitive that the second template is more specialized than the first. However, the current rules make them unordered. In 13.10.3.5 [temp.deduct.partial] paragraph 4, we have P as const C* and A as const char (&)[N]. Paragraph 5 transforms A to const char[N]. Finally, paragraph 7 removes top-level cv-qualification; since a cv-qualified array element type is considered to be cv-qualification of the array (6.8.5 [basic.type.qualifier] paragraph 5, cf issue 1059), A becomes char[N]. P remains const C*, so deduction fails because of the missing const in A.

Notes from the April, 2013 meeting:

CWG agreed that the const should be preserved in the array type.




2328. Unclear presentation style of template argument deduction rules

Section: 13.10.3.6  [temp.deduct.type]     Status: drafting     Submitter: Richard Smith     Date: 2016-10-11

The presentation style of 13.10.3.6 [temp.deduct.type] paragraph 8 results in a specification that is unclear, needlessly verbose, and incomplete. Specific problems include:




2172. Multiple exceptions with one exception object

Section: 14.4  [except.handle]     Status: drafting     Submitter: Richard Smith     Date: 2015-09-14

During the discussion of issue 2098 it was observed that multiple exceptions may share a single exception object via std::exception_ptr. It is not clear that the current wording handles that case correctly.




2219. Dynamically-unreachable handlers

Section: 14.4  [except.handle]     Status: drafting     Submitter: 2016-01-04     Date: Richard Smith

Consider the following example:

  #include <cstdio>
  #include <cstdlib>

  void f() {
    struct X {
     ~X() {
       std::puts("unwound");
       std::exit(0);
     }
    } x;
    throw 0;
  }

  int main(int argc, char**) {
    try {
      f();
    } catch (int) {
      std::puts("caught");
    }
  }

According to the Standard, this should print unwound and exit. Current optimizing implementations call terminate(), because:

More abstractly, before calling terminate, we're required to check whether there is an active handler for an exception of type int, and in some sense there is not (because the handler in main is dynamically unreachable).

There seem to be three possible solutions:

  1. Change the standard to say that terminate() is a valid response to this situation [this seems problematic, as any non-returning destructor now risks program termination, but is in fact the status quo on multiple implementations and does not seem to have resulted in any bug reports]

  2. Always fully unwind before calling terminate() [this significantly harms debugability of exceptions]

  3. Teach the compilers to not optimize out unreachable exception handlers [for some implementations, this is “remove, redesign and reimplement middle-end support for EH”-level difficult, and harms the ability to optimize code involving catch handlers]




1718. Macro invocation spanning end-of-file

Section: 15.6  [cpp.replace]     Status: drafting     Submitter: David Krauss     Date: 2013-07-23     Liaison: WG14

Although it seems to be common implementation practice to reject a macro invocation that begins in a header file and whose closing right parenthesis appears in the file that included it, there does not seem to be a prohibition of this case in the specification of function-style macros. Should this be accepted?

Notes from the February, 2014 meeting:

CWG agreed that macro invocations spanning file boundaries should be prohibited. Resolution of this issue should be coordinated with WG14.




2003. Zero-argument macros incorrectly specified

Section: 15.6  [cpp.replace]     Status: drafting     Submitter: Richard Smith     Date: 2014-09-12

According to 15.6 [cpp.replace] paragraph 4,

If the identifier-list in the macro definition does not end with an ellipsis, the number of arguments (including those arguments consisting of no preprocessing tokens) in an invocation of a function-like macro shall equal the number of parameters in the macro definition.

That is, a sequence of no preprocessing tokens counts as an argument. That phrasing has problems with zero-argument function-like macros, e.g.,

  #define M()
  M();

M is defined as having no parameters but the invocation has one (empty) argument, which does not match the number of parameters in the definition.




1709. Stringizing raw string literals containing newline

Section: 15.6.3  [cpp.stringize]     Status: drafting     Submitter: David Krauss     Date: 2013-07-01

Stringizing a raw string literal containing a newline produces an invalid (unterminated) string literal and hence results in undefined behavior. It should be specified that a newline in a string literal is transformed to the two characters '\' 'n' in the resulting string literal.

A slightly related case involves stringizing a bare backslash character: because backslashes are only escaped within a string or character literal, a stringized bare backslash becomes "\", which is invalid and hence results in undefined behavior.




1889. Unclear effect of #pragma on conformance

Section: 15.9  [cpp.pragma]     Status: drafting     Submitter: James Widman     Date: 2014-03-05

According to 15.9 [cpp.pragma] paragraph 1, the effect of a #pragma is to cause

the implementation to behave in an implementation-defined manner. The behavior might cause translation to fail or cause the translator or the resulting program to behave in a non-conforming manner.

It should be clarified that the extent of the non-conformance is limited to the implementation-defined behavior.




2181. Normative requirements in an informative Annex

Section: Clause Annex B  [implimits]     Status: drafting     Submitter: Sean Hunt     Date: 2015-10-18

According to Clause Annex B [implimits] paragraph 1,

Because computers are finite, C++ implementations are inevitably limited in the size of the programs they can successfully process. Every implementation shall document those limitations where known.

Because Annex Clause Annex B [implimits] is informative, not normative, it should not use “shall.”




1279. Additional differences between C++ 2003 and C++ 2011

Section: C.6  [diff.cpp03]     Status: drafting     Submitter: Nikolay Ivchenkov     Date: 2011-03-27

A number of differences between C++03 and C++11 were omitted from C.6 [diff.cpp03]:

Additional note (January, 2012):

In addition to the items previously mentioned, access declarations were removed from C++11 but are not mentioned in C.6 [diff.cpp03].

Proposed (partial) resolution (February, 2012):

Add the following as a new section in C.6 [diff.cpp03]:

C.2.5 11.8 [class.access]: member access control pdiff.cpp03.class.access

Change: Remove access declarations.

Rationale: Removal of feature deprecated since C++ 1998.

Effect on original feature: Valid C++ 2003 code that uses access declarations is ill-formed in this International Standard. Instead, using-declarations (9.9 [namespace.udecl]) can be used.






Issues with "Open" Status


783. Definition of “argument”

Section: Clause 3  [intro.defs]     Status: open     Submitter: UK     Date: 3 March, 2009

N2800 comment UK 3

The definition of an argument does not seem to cover many assumed use cases, and we believe that is not intentional. There should be answers to questions such as: Are lambda-captures arguments? Are type names in a throw-spec arguments? “Argument” to casts, typeid, alignof, alignas, decltype and sizeof? why in x[arg] arg is not an argument, but the value forwarded to operator[]() is? Does not apply to operators as call-points not bounded by parentheses? Similar for copy initialization and conversion? What are deduced template “arguments?” what are “default arguments?” can attributes have arguments? What about concepts, requires clauses and concept_map instantiations? What about user-defined literals where parens are not used?




949. Requirements for freestanding implementations

Section: 4.1  [intro.compliance]     Status: open     Submitter: Detlef Vollman     Date: 2 August, 2009

According to 4.1 [intro.compliance] paragraph 7,

A freestanding implementation is one in which execution may take place without the benefit of an operating system, and has an implementation-defined set of libraries that includes certain language-support libraries (16.4.2.5 [compliance]).

This definition links two relatively separate topics: the lack of an operating system and the minimal set of libraries. Furthermore, 6.9.3.1 [basic.start.main] paragraph 1 says:

[Note: in a freestanding environment, start-up and termination is implementation-defined; start-up contains the execution of constructors for objects of namespace scope with static storage duration; termination contains the execution of destructors for objects with static storage duration. —end note]

It would be helpful if the two characteristics (lack of an operating system and restricted set of libraries) were named separately and if these statements were clarified to identify exactly what is implementation-defined.

Notes from the October, 2009 meeting:

The CWG felt that it needed a specific proposal in a paper before attempting to resolve this issue.




2776. Substitution failure and implementation limits

Section: 4.1.1  [intro.compliance.general]     Status: open     Submitter: Corentin Jabot     Date: 2023-07-27     Liaison: EWG

Are there behavioral bounds in case an implementation limit is encountered? For example, a constant expression may fail to be recognized as such due to an implementation limit (e.g. a recursion or step limit), causing overload resolution to pick a different overload. Is that acceptable?

Possible resolution:

  1. Change in 4.1.1 [intro.compliance.general] paragraph 2 as follows:

    Although this document states only requirements on C++ implementations, those requirements are often easier to understand if they are phrased as requirements on programs, parts of programs, or execution of programs as specified in the rules in Clause 5 [lex] through Clause 33 [thread] and Annex D. Such requirements have the following meaning:
    • If a program contains a violation of a rule for which no diagnostic is required, this document places no requirement on implementations with respect to that program.

    • Otherwise, if an implementation limit (Annex B) is reached during translation, an implementation shall reject the program.

      Recommended practice: An implementation should document limits where they are known, and should issue a diagnostic in cases where it can reasonably detect that the implementation limit is reached.

    • If a program contains no violations of the rules in Clause 5 [lex] through Clause 33 [thread] and Annex D, a conforming implementation shall, within its resource limits as described in Annex B, accept and correctly execute [ Footnote: ... ] that program.
    • If a program contains a violation of a rule for which no diagnostic is required, this document places no requirement on implementations with respect to that program.
    • Otherwise, if a that program contains a violation of any diagnosable rule or an occurrence of a construct described in this document as “conditionally-supported” when the implementation does not support that construct, a conforming implementation shall issue at least one diagnostic message.
    • Otherwise, a conforming implementation shall accept and correctly execute that program. [ Note: "Correct execution" can include undefined behavior, depending on the data being processed; see Clause 3 [intro.defs] and 4.1.2 [intro.abstract]. -- end note ]
  2. Add a new paragraph after 4.1.2 [intro.abstract] paragraph 6 as follows:

    [Note 2 : More stringent correspondences between abstract and actual semantics can be defined by each implementation. -- end note]

    If an implementation limit (Annex B) is reached, the behavior is undefined.

    Recommended practice: An implementation should document limits where they are known and abort the execution of the program in cases where it can reasonably detect that the implementation limit is reached.

  3. Change in 7.7 [expr.const] paragraph 5 as follows:

    • ...
    • an expression that would exceed the implementation-defined limits (see Annex B);
    • an operation that would have undefined behavior as specified in Clause 4 [intro] through Clause 15 [cpp], excluding 9.12.3 [dcl.attr.assume] and exceeding an implementation limit (4.1.2 [intro.abstract]); [ Footnote: ... ]
      [ Example:
        constexpr bool f(int x) { return (x == 0) || f(x-1); }
        const bool g = f(60000);    // well-formed static initialization (6.9.3.2 [basic.start.static]);
                                    // program can be rejected because implementation limit is reached
      
      -- end example ]
    • ...
  4. Change in 13.9.2 [temp.inst] paragraph 16 as follows:

    There is an implementation-defined quantity that specifies the limit on the total depth of recursive instantiations (Annex B), which could involve more than one template. The result of an infinite recursion in instantiation is undefined.

CWG 2023-08-25

For the example in change 3, implementations currently switch to dynamic initialization when their implementation limits related to constant evaluation are exceeded. This might be surprising to users, because dynamic initialization can exhibit order-of-initialization issues. It might be less harmful to reject such situations as ill-formed. Furthermore, it is unclear whether implementations can reliably determine that an implementation limit is reached, before crashing.

CWG is requesting EWG guidance via paper issue #1631.

EWG 2023-11-07

EWG is soliciting a paper to make this either ill-formed, no diagnostic required, or well-formed.




2779. Restrictions on the ordinary literal encoding

Section: 5.3  [lex.charset]     Status: open     Submitter: Jim X     Date: 2023-03-28

There are no restrictions on the implementation's choice of ordinary literal encoding. However, there is an implicit assumption that a code unit value must fit into a char.

Tangentially related to that, "cannot be encoded as a single code unit" could be interpreted as referring to the values of the code units as opposed to the fact that multiple code units might be needed.

Possible resolution:

  1. Change in 5.3 [lex.charset] paragraph 8 as follows and add to the index of implementation-defined behavior:

    A code unit is an integer value of character type (6.8.2 [basic.fundamental]). Characters in a character-literal other than a multicharacter or non-encodable character literal or in a string-literal are encoded as a sequence of one or more code units, as determined by the encoding-prefix (5.13.3 [lex.ccon], 5.13.5 [lex.string]); this is termed the respective literal encoding. The ordinary literal encoding is the implementation-defined encoding applied to an ordinary character or string literal; its code units are of type unsigned char. The wide literal encoding is the implementation-defined encoding applied to a wide character or string literal; its code units are of type wchar_t.
  2. Change in 5.13.3 [lex.ccon] bullet 3.1 as follows:

    • A character-literal with a c-char-sequence consisting of a single basic-c-char , simple-escape-sequence, or universal-character-name is the code unit value of the specified character as encoded in the literal's associated character encoding. If the specified character lacks representation in the literal's associated character encoding or if it cannot be encoded as a single code unit is encoded with multiple code units, then the program is ill-formed.
    • ...



2818. Use of predefined reserved identifiers

Section: 5.10  [lex.name]     Status: open     Submitter: Jiang An     Date: 2023-01-18

Subclause 5.10 [lex.name] paragraph 3 specifies:

In addition, some identifiers appearing as a token or preprocessing-token are reserved for use by C++ implementations and shall not be used otherwise; no diagnostic is required.

That implies that uses of standard-specified predefined macros (15.11 [cpp.predefined]) or feature-test macros (17.3.2 [version.syn]) make the program ill-formed. This does not appear to be the intent.

Possible resolution:

Change in 5.10 [lex.name] paragraph 3 as follows:

In addition, some identifiers appearing as a token or preprocessing-token are reserved for use by C++ implementations and shall not be used otherwise; no diagnostic is required.



2752. Excess-precision floating-point literals

Section: 5.13.4  [lex.fcon]     Status: open     Submitter: Peter Dimov     Date: 2023-06-29     Liaison: EWG

Consider:

  int main()
  {
    constexpr auto x = 3.14f;
    assert( x == 3.14f );         // can fail?
    static_assert( x == 3.14f );  // can fail?
  }

Can a conforming implementation represent a floating-point literal with excess precision, causing the comparisons to fail?

Subclause 5.13.4 [lex.fcon] paragraph 3 specifies:

If the scaled value is not in the range of representable values for its type, the program is ill-formed. Otherwise, the value of a floating-point-literal is the scaled value if representable, else the larger or smaller representable value nearest the scaled value, chosen in an implementation-defined manner.

This phrasing leaves little leeway for excess precision. In contrast, C23 (WG14 N3096) specifies in section 6.4.4.2 paragraph 6:

The values of floating constants may be represented in greater range and precision than that required by the type (determined by the suffix); the types are not changed thereby. ...

Subclause 7.1 [expr.pre] paragraph 6 allows excess precision for floating-point computations (including their operands):

The values of the floating-point operands and the results of floating-point expressions may be represented in greater precision and range than that required by the type; the types are not changed thereby. [ Footnote: The cast and assignment operators must still perform their specific conversions as described in 7.6.1.4 [expr.type.conv], 7.6.3 [expr.cast], 7.6.1.9 [expr.static.cast] and 7.6.19 [expr.ass]. -- end footnote ]

Taken together, that means that 314.f / 100.f can be computed and represented more precisely than 3.14f, which is hard to justify. The footnote appears to imply that (float)3.14f is required to yield a value with float precision, but that conversion (eventually) ends up at 9.4.1 [dcl.init.general] bullet 16.9:

This phrasing leaves no permission to discard excess precision when converting from a float value to type float ("... is the value...").

However, if initialization is intended to drop excess precision, then an overloaded operator returning float can never behave like a built-in operation with excess precision, because returning a value means initializing the return value.

The C++ standard library inherits the FLT_EVAL_METHOD macro from the C standard library. C23 (WG14 N3096) specifies it as follows in section 5.2.4.2.2:

0 evaluate all operations and constants just to the range and precision of the type;
1 evaluate operations and constants of type float and double to the range and precision of the double type, evaluate long double operations and constants to the range and precision of the long double type;
2 evaluate all operations and constants to the range and precision of the long double type.

Taken together, a conforming C++ implementation cannot define FLT_EVAL_METHOD to 1 or 2, because literals (= "constants") cannot be represented with excess precision in C++.

Additional notes (June, 2023)

Forwarded to EWG via cplusplus/papers#1584, by decision of the CWG chair.




2766. Repeated evaluation of a string-literal may yield different objects

Section: 5.13.5  [lex.string]     Status: open     Submitter: Balog Pal     Date: 2023-07-15

Prior to the resolution of issue 1823 (incorporated into C++17), the specification required in 9.2.3 [dcl.fct.spec] paragraph 4:

A string literal in the body of an extern inline function is the same object in different translation units.

That was changed to the following specification in 5.13.5 [lex.string] paragraph 9:

Evaluating a string-literal results in a string literal object with static storage duration (6.7.5 [basic.stc]). ... whether successive evaluations of a string-literal yield the same or a different object is unspecified.

The treatment of string literal objects was harmonized with backing arrays in P2752R3 (approved in June, 2023) and issue 2753.

The rationale for the change made by issue 1823 was deviating implementation practice: Implementations do not unify string literal objects in inline functions or template instantiations across different translation units.

However, that was a silent behavior change for examples such as:

  const char *f() { return "abc"; }
  bool b = f() == f();    // guaranteed true prior to CWG1823, now unspecified

The matter should be revisited in light of this new information.




1266. user-defined-integer-literal overflow

Section: 5.13.9  [lex.ext]     Status: open     Submitter: Michael Wong     Date: 2011-03-20

The decimal-literal in a user-defined-integer-literal might be too large for an unsigned long long to represent (in implementations with extended integer types). In such cases, the original intent appears to have been to call a raw literal operator or a literal operator template; however, the existing wording of 5.13.9 [lex.ext] paragraph 3 always calls the unsigned long long literal operator if it exists, regardless of the value of the decimal-literal.




1209. Is a potentially-evaluated expression in a template definition a “use?”

Section: 6.3  [basic.def.odr]     Status: open     Submitter: Johannes Schaub     Date: 2010-10-08

Consider the following complete program:

    void f();
    template<typename T> void g() { f(); }
    int main() { }

Must f() be defined to make this program well-formed? The current wording of 6.3 [basic.def.odr] does not make any special provision for expressions that appear only in uninstantiated template definitions.

(See also issue 1254.)


2745. Dependent odr-use in generic lambdas

Section: 6.3  [basic.def.odr]     Status: open     Submitter: Shafik Yaghmour     Date: 2022-12-13

Default template arguments of generic lambdas can refer to local variables. It is unclear whether the potential odr-use is checked when parsing the template definition or when instantiating the template.

There is wide implementation divergence.

Possible resolution:

Insert a new paragraph before 6.3 [basic.def.odr] paragraph 11:

[ Example:

  void g() {
    constexpr int x = 1;
    auto lambda = [] <typename T, T V = x> {};  // OK
    lambda.operator()<int, 1>();         // OK, does not consider x at all
    lambda.operator()<int>();            // OK, does not odr-use x
    lambda.operator()<const int&>();     // error: odr-uses x from a context where x is not odr-usable
  }

  void h() {
    constexpr int x = 1;
    auto lambda = [] <typename T> { (T)x; };  // OK
    lambda.operator()<int>();            // OK, does not odr-use x
    lambda.operator()<void>();           // OK, does not odr-use x
    lambda.operator()<const int&>();     // error: odr-uses x from a context where x is not odr-usable
  }

-- end example ]

Every program shall contain at least one definition of every function or variable ...




2781. Unclear recursion in the one-definition rule

Section: 6.3  [basic.def.odr]     Status: open     Submitter: Johannes Schaub     Date: 2023-08-19

(From submission #402.)

Consider the following tokens appearing in multiple translation units:

 inline void f() {
   int a;
   int b = a;
 }

Does f violate the one-definition rule?

We have this check in 6.3 [basic.def.odr] paragraph 14.5:

Does a refer to the same entity in the several definitions of f? Subclause 6.3 [basic.def.odr] paragraph 16 specifies:

These requirements also apply to corresponding entities defined within each definition of D (including the closure types of lambda-expressions, but excluding entities defined within default arguments or default template arguments of either D or an entity not defined within D). For each such entity and for D itself, the behavior is as if there is a single entity with a single definition, including in the application of these requirements to other entities.

Thus, the requirements apply recursively to the definitions of a, but it is unclear whether the conclusion "as if there is a single entity with a single definition" is reached at each level of the recursion separately.

Suggested resolution:

Change in 6.3 [basic.def.odr] paragraph 16 as follows:

If these requirements are satisfied, the behavior for D is as if there is a single entity with a single definition, including in the application of these requirements to other entities. These requirements This behavior also apply applies to corresponding entities defined within each definition of D (including the closure types of lambda-expressions, but excluding entities defined within default arguments or default template arguments of either D or an entity not defined within D). For each such entity and for D itself, the behavior is as if there is a single entity with a single definition, including in the application of these requirements to other entities.



2782. Treatment of closure types in the one-definition rule

Section: 6.3  [basic.def.odr]     Status: open     Submitter: Brian Bi     Date: 2023-07-20

Consider:

  inline auto lambda = []{}; // same in different translation units or not?

This can be observed, for example, through the following variable template:

  template<class T> int v;

Is &v<decltype(lambda)> the same address in every translation unit?

Possible resolution:

  1. Change in 6.3 [basic.def.odr] paragraph 14 as follows:

    For any definable item D with definitions in multiple translation units,
    • if D is a non-inline non-templated function or variable, or
    • if the definitions in different translation units do not satisfy the following requirements,
    the program is ill-formed; a diagnostic is required only if the definable item is attached to a named module and a prior definition is reachable at the point where a later definition occurs. Given such an item, for all definitions of D, or, if D is an unnamed enumeration, for all definitions of D that are reachable at any given program point, the following requirements shall be satisfied, where the definition of a closure type is considered to consist of the sequence of tokens of the corresponding lambda-expression.
    • ...
    • Each such definition shall consist of the same sequence of tokens, where the definition of a closure type is considered to consist of the sequence of tokens of the corresponding lambda-expression.
    • ...
  2. Add another example after example 6, immediately before 6.3 [basic.def.odr] paragraph 18:

    [ Example:
      inline decltype([]{}) v1;
      inline auto v2 = []{};
    
    If the definition of v1 appears in multiple translation units, the program is ill-formed, no diagnostic required, because each definition declares v1 to have a different type. If the definition of v2 appears in multiple translation units, the behavior of the program is as if there is only one definition, and only a definition can supply an initializer; therefore the behavior is as if there is only one initializer. Therefore, v2 has the same type in every translation unit. -- end example]

    If, at any point in the program, there is more than one reachable unnamed enumeration definition in the same scope...




2488. Overloading virtual functions and functions with trailing requires-clauses

Section: 6.4.1  [basic.scope.scope]     Status: open     Submitter: Jiang An     Date: 2020-08-19

According to 6.4.1 [basic.scope.scope] paragraph 3,

Two declarations correspond if they (re)introduce the same name, both declare constructors, or both declare destructors, unless

This would indicate that a virtual function (which cannot have a trailing requires-clause, per 11.7.3 [class.virtual] paragraph 6) can be overloaded with a non-virtual member function with the same parameter type list but with a trailing requires-clause. However, this is not implementable on some ABIs, since the mangling of the two functions would be the same. For example:


  #include <type_traits>
  template<class T>
  struct Foo {
     virtual void fun() const {}
     void fun() const requires std::is_object_v<T> {}
  };
  int main() {
    Foo<int>{}.fun();
  }

Should such overloading be ill-formed or conditionally-supported, or should the current rules be kept?

Rationale (August, 2021):

CWG felt that the current rules are correct; it simply means that only the virtual function can be called, and all other references are simply ambiguous. (See also issue 2501 for a related question dealing with explicit instantiation.

Notes from the November, 2021 teleconference:

The issue has been reopened in response to additional discussion.

CWG 2022-11-11

This is related to issue 2501. CWG solicits a paper to address this issue.




2788. Correspondence and redeclarations

Section: 6.4.1  [basic.scope.scope]     Status: open     Submitter: Corentin Jabot     Date: 2023-08-09

Consider:

  struct S {
    void f() &;
  };
  void S::f(this S&) {}

Both declarations of S::f correspond (6.4.1 [basic.scope.scope] paragraph 4), but are ill-formed according to 6.6 [basic.link] paragraph 1, because the functions are not of the same type:

For any two declarations of an entity E:

A similar situation arises for the following example:

  struct S {
    void g() &;
  };
  void S::g() { }

Possible resolution:

Add a note in 6.4.1 [basic.scope.scope] paragraph 4 as follows:

[ Note: Two function declarations with different ref-qualifiers or parameter-type-lists do not have the same type even if they correspond (6.6 [basic.link]). -- end note ]
[ Example 2:
  typedef int Int;
  ...
   
    void m();
    void n();
  };

 X::m() & {}       // error: redeclaration of X::m with a different type
 X::n(this X&) {}  // error: redeclaration of X::n with a different type



380. Definition of "ambiguous base class" missing

Section: 6.5.2  [class.member.lookup]     Status: open     Submitter: Jason Merrill     Date: 22 Oct 2002

The term "ambiguous base class" doesn't seem to be actually defined anywhere. 6.5.2 [class.member.lookup] paragraph 7 seems like the place to do it.




2670. Programs and translation units

Section: 6.6  [basic.link]     Status: open     Submitter: Gabriel dos Reis     Date: 2022-12-21

Subclause 6.6 [basic.link] paragraph 1 specifies:

A program consists of one or more translation units (5.1 [lex.separate]) linked together. A translation unit consists of a sequence of declarations.

Subclause 5.1 [lex.separate] paragraph 1 defines "translation unit":

A source file together with all the headers (16.4.2.3 [headers]) and source files included (15.3 [cpp.include]) via the preprocessing directive #include, less any source lines skipped by any of the conditional inclusion (15.2 [cpp.cond]) preprocessing directives, is called a translation unit.

Subclause 5.2 [lex.phases] paragraph 7 first mentions the "translation" of translation units:

Whitespace characters separating tokens are no longer significant. Each preprocessing token is converted into a token (5.6 [lex.token]). The resulting tokens are syntactically and semantically analyzed and translated as a translation unit.

However, 5.2 [lex.phases] paragraph 8 introduces "instantiation units" and 5.2 [lex.phases] paragraph 9 specifies:

Translated translation units and instantiation units are combined as follows:

and 5.2 [lex.phases] paragraph 9 specifies:

All external entity references are resolved. Library components are linked to satisfy external references to entities not defined in the current translation. All such translator output is collected into a program image which contains information needed for execution in its execution environment.

The term "linking" in 5.2 [lex.phases] comes after translated translation units and instantiation units are combined, yet 6.6 [basic.link] paragraph 1 states that (untranslated) translation units are linked to form a program. That seems inconsistent.

Additional notes (February, 2023)

See also issue 2518, which introduced the term "preprocessing translation unit" to remove the conflict between 6.6 [basic.link] paragraph 1 and 5.1 [lex.separate] paragraph 1.




2706. Repeated structured binding declarations

Section: 6.6  [basic.link]     Status: open     Submitter: Jim X     Date: 2023-02-13

Consider:

  struct A {
    int a;
  };
  struct B {
    int b;
  };
  auto&& [x] = A{}; //#1
  auto&& [x] = B{}; //#2

A rule is missing to make such repeated structured binding declarations ill-formed.

Suggested resolution:

Change in 6.6 [basic.link] paragraph 11 as follows:

For any two declarations of an entity E:



1953. Data races and common initial sequence

Section: 6.7.1  [intro.memory]     Status: open     Submitter: Faisal Vali     Date: 2014-06-23

According to 6.7.1 [intro.memory] paragraph 3,

A memory location is either an object of scalar type or a maximal sequence of adjacent bit-fields all having non-zero width. [Note: Various features of the language, such as references and virtual functions, might involve additional memory locations that are not accessible to programs but are managed by the implementation. —end note] Two or more threads of execution (6.9.2 [intro.multithread]) can update and access separate memory locations without interfering with each other.

It is not clear how this relates to the permission granted in 11.4 [class.mem] paragraph 18 to inspect the common initial sequence of standard-layout structs that are members of a standard-layout union. If one thread is writing to the common initial sequence and another is reading from it via a different struct, that should constitute a data race, but the current wording does not clearly state that.




2334. Creation of objects by typeid

Section: 6.7.2  [intro.object]     Status: open     Submitter: Chris Hallock     Date: 2017-01-30

The list of ways that an object may be created in 6.7.2 [intro.object] paragraph 1 does not include creation of type_info objects by typeid expressions, but 7.6.1.8 [expr.typeid] does not appear to require that such objects exist before they are referenced. Should the list in 6.7.2 [intro.object] be extended to include this case?




2744. Multiple objects of the same type at the same address

Section: 6.7.2  [intro.object]     Status: open     Submitter: Chris Hallock     Date: 2023-06-08

(From thread beginning here.)

Consider:

  #include <new>

  struct A { unsigned char buf[1]; };
  static_assert(sizeof(A) == 1); // A can fit within A::buf

  int main()
  {
    A x{};
    new (x.buf) A{};
  }

A::buf provides storage for another A object. Thus, there are now two objects of type A within lifetime, which is inconsistent with the goal expressed by 6.7.2 [intro.object] paragraph 9.

Suggested resolution:

Change in 6.7.2 [intro.object] paragraph 3 as follows:

If a complete object of type T is created (7.6.2.8 [expr.new]) in storage associated with another object e of type “array of N unsigned char” or of type “array of N std::byte” (17.2.1 [cstddef.syn]), that array provides storage for the created object if:



2765. Address comparisons between potentially non-unique objects during constant evaluation

Section: 6.7.2  [intro.object]     Status: open     Submitter: CWG     Date: 2023-07-14

The (arguably) expanded treatment of backing arrays and string literals as potentially non-unique objects in issue 2753 lead to the question how the resulting address comparisons are treated during constant evaluation.

Subclause 7.7 [expr.const] bullet 5.24 specifies:

An expression E is a core constant expression unless the evaluation of E, following the rules of the abstract machine (6.9.1 [intro.execution]), would evaluate one of the following:

This phrasing is understood to refer to explicitly unspecified outcomes only. The treatment of an example such as

  constexpr bool b = "abc" == "abc";

is unclear, given that identical string literals may or may not yield distinct string literal objects.

The assumption that equality comparison of std::string_view would compare addresses as a short-cut before comparing the character sequence could not be confirmed (23.2.2 [char.traits.require], 23.3.3.8 [string.view.ops] paragraph 12).




419. Can cast to virtual base class be done on partially-constructed object?

Section: 6.7.3  [basic.life]     Status: open     Submitter: Judy Ward     Date: 2 June 2003

Consider

  extern "C" int printf (const char *,...);

  struct Base { Base();};
  struct Derived: virtual public Base {
     Derived() {;}
  };

  Derived d;
  extern Derived& obj = d;

  int i;

  Base::Base() {
    if ((Base *) &obj) i = 4;
    printf ("i=%d\n", i);
  }

  int main() { return 0; }

11.9.5 [class.cdtor] paragraph 2 makes this valid, but 6.7.3 [basic.life] paragraph 5 implies that it isn't valid.

Steve Adamczyk: A second issue:

  extern "C" int printf(const char *,...);
  struct A                      { virtual ~A(); int x; };
  struct B : public virtual A   { };
  struct C : public B           { C(int); };
  struct D : public C           { D(); };

  int main()                    { D t; printf("passed\n");return 0; }

  A::~A()                       {}
  C::C(int)                     {}
  D::D() : C(this->x)           {}

Core issue 52 almost, but not quite, says that in evaluating "this->x" you do a cast to the virtual base class A, which would be an error according to 11.9.5 [class.cdtor] paragraph 2 because the base class B constructor hasn't started yet. 7.6.1.5 [expr.ref] should be clarified to say that the cast does need to get done.

James Kanze submitted the same issue via comp.std.c++ on 11 July 2003:

Richard Smith: Nonsense. You can use "this" perfectly happily in a constructor, just be careful that (a) you're not using any members that are not fully initialised, and (b) if you're calling virtual functions you know exactly what you're doing.

In practice, and I think in intent, you are right. However, the standard makes some pretty stringent restrictions in 6.7.3 [basic.life]. To start with, it says (in paragraph 1):

The lifetime of an object is a runtime property of the object. The lifetime of an object of type T begins when: The lifetime of an object of type T ends when:
(Emphasis added.) Then when we get down to paragraph 5, it says:

Before the lifetime of an object has started but after the storage which the object will occupy has been allocated [which sounds to me like it would include in the constructor, given the text above] or, after the lifetime of an object has ended and before the storage which the object occupied is reused or released, any pointer that refers to the storage location where the object will be or was located may be used but only in limited ways. [...] If the object will be or was of a non-POD class type, the program has undefined behavior if:

[...]

I can't find any exceptions for the this pointer.

Note that calling a non-static function in the base class, or even constructing the base class in initializer list, involves an implicit conversion of this to a pointer to the base class. Thus undefined behavior. I'm sure that this wasn't the intent, but it would seem to be what this paragraph is saying.




2258. Storage deallocation during period of destruction

Section: 6.7.3  [basic.life]     Status: open     Submitter: Richard Smith     Date: 2016-04-12

What happens if the storage for an object is deallocated in its period of destruction? Consider:

  struct Base {
    virtual ~Base() {
      ::operator delete(this);
    }
    void operator delete(void*) {}
  };

  struct Derived : Base {};

  int main() {
    delete new Derived;
  } 

This ought to be undefined behavior, but the standard is silent on the matter.

Notes from the December, 2016 teleconference:

The consensus view was that this should be undefined behavior.

Additional notes (July, 2023)

This issue is a subset of issue 2757.




2514. Modifying const subobjects

Section: 6.7.3  [basic.life]     Status: open     Submitter: Jiang An     Date: 2021-11-07     Liaison: SG12

The change in C++20 for RU007 allows transparently replacing a const subobject whose complete object is not const, and the new object can be non-const. However, if the reuse of the object has not happened, modifying such subobjects is still undefined behavior.

This restriction causes problems in the implementation of std::map and std::unordered_map; see this bug report. Here, the key_type objects in map containers are const, and implementations generally can't replace these objects after construction.

Perhaps these restrictions can be relaxed to assist in this case: if

a const subobject could be modified.

(Is it meaningful to allow a new-expression like new const int(42) to create cv-qualified objects? Perhaps such objects should be unqualified, while maintaining the cv-qualification in the type of the expression?)

Notes from the November, 2022 meeting

The advice of SG12 is solicited; see cplusplus/papers#1395.




2676. Replacing a complete object having base subobjects

Section: 6.7.3  [basic.life]     Status: open     Submitter: Richard Smith     Date: 2022-12-06

Base subobjects cannot be transparently replaced with complete objects, as specified in 6.7.3 [basic.life] bullet 8.4:

An object o1 is transparently replaceable by an object o2 if:

However, that bullet is over-reaching, because it disallows:

  struct A { int n; };
  struct B : A {};
  B b;
  new (&b) B { {5} };  // New A base class does not transparently replace existing A base class due to /8.4.
  int k = b.n;  // UB: member n of A base class is outside its lifetime

See issue 2677 for a suggested resolution.

Additional notes (February, 2023)

Consider this example:

  struct A {
   int n;
   char c;
   // tail padding
  };
  struct B {
   [[no_unique_address]] A a;
   char in_tail_padding[3];
  };

  B b;
  void f() {
   // Transparently replaces old member, potentially overwriting the data in the tail padding!
   new (&b.a) A{};
  }

The suggestions do not address this example.




2821. Lifetime, zero-initialization, and dynamic initialization

Section: 6.7.3  [basic.life]     Status: open     Submitter: Jan Schultke     Date: 2023-07-24

Consider:

  int i = i;

According to 6.9.3.2 [basic.start.static] paragraph 2, i is zero-initialized and then dynamic initialization is applied. However, it is unclear whether the lifetime of i has started at the point when the dynamic initialization occurs. According to 6.7.3 [basic.life] paragraph 1:

... The lifetime of an object of type T begins when: except ...

Possible directions:

The example in 6.9.3.2 [basic.start.static] paragraph 3 suggests the first option.




365. Storage duration and temporaries

Section: 6.7.5  [basic.stc]     Status: open     Submitter: James Kanze     Date: 24 July 2002

There are several problems with 6.7.5 [basic.stc]:

Steve Adamczyk: There may well be an issue here, but one should bear in mind the difference between storage duration and object lifetime. As far as I can see, there is no particular problem with temporaries having automatic or static storage duration, as appropriate. The point of 6.7.7 [class.temporary] is that they have an unusual object lifetime.

Notes from Ocrober 2002 meeting:

It might be desirable to shorten the storage duration of temporaries to allow reuse of them. The as-if rule allows some reuse, but such reuse requires analysis, including noting whether the addresses of such temporaries have been taken.

Notes from the August, 2011 meeting:

The CWG decided that further consideration of this issue would be deferred until someone produces a paper explaining the need for action and proposing specific changes.

See also issue 1634.




1682. Overly-restrictive rules on function templates as allocation functions

Section: 6.7.5.5.2  [basic.stc.dynamic.allocation]     Status: open     Submitter: Jason Merrill     Date: 2009-03-03

Requirements for allocation functions are given in 6.7.5.5.2 [basic.stc.dynamic.allocation] paragraph 1:

An allocation function can be a function template. Such a template shall declare its return type and first parameter as specified above (that is, template parameter types shall not be used in the return type and first parameter type). Template allocation functions shall have two or more parameters.

There are a couple of problems with this description. First, it is instances of function templates that can be allocation functions, not the templates themselves (cf 6.7.5.5.3 [