Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++17 status.

2380. May<cstdlib> providelong ::abs(long) andlong long ::abs(long long)?

Section: 16.4.2.3[headers]Status:C++17Submitter: Richard SmithOpened: 2014-03-31Last modified: 2017-07-30

Priority:2

View all otherissues in [headers].

View all issues withC++17 status.

Discussion:

[depr.c.headers] p3 says:

[Example: The header<cstdlib> assuredly provides its declarations and definitions within the namespacestd. It may also provide these names within the global namespace. The header<stdlib.h> assuredlyprovides the same declarations and definitions within the global namespace, much as in the C Standard. Itmay also provide these names within the namespacestd. —end example]

This suggests that<cstdlib> may provide::abs(long) and::abs(long long). But this seems like it might contradict the normative wording of 16.4.2.3[headers] p4:

Except as noted in Clauses 18 through 30 and Annex D, the contents of each headercname shall be the sameas that of the corresponding headername.h, as specified in the C standard library (1.2) or the C UnicodeTR, as appropriate, as if by inclusion. In the C++ standard library, however, the declarations (except fornames which are defined as macros in C) are within namespace scope (3.3.6) of the namespacestd. It isunspecified whether these names are first declared within the global namespace scope and are then injectedinto namespacestd by explicit using-declarations (7.3.3).

Note that this allows<cstdlib> to provide::abs(int), but does not obviously allow::abs(long) nor::abs(long long), since they are not part of the headerstdlib.h as specified in the C standard library.

29.7[c.math] p7 adds signaturesstd::abs(long) andstd::abs(long long), but not in a way that seems to allow::abs(long) and::abs(long long) to be provided.

I think the right approach here would be to allow<cstdlib> to either provide no::abs declaration, or to provide all three declarations from namespacestd, but it should not be permitted to provide onlyint abs(int). Suggestion:

Change in 16.4.2.3[headers] p4:

[…]. It is unspecified whether these names(including any overloads added in Clauses 18 through 30 and Annex D) are first declared within the global namespace scope and are then injected into namespacestd by explicit using-declarations (7.3.3).

[2015-05, Lenexa]

MC: do we need to defer this?
PJP: just need to get my mind around it, already playing dirty games here, my reaction is just do it as it will help C++
STL: this is safe
TP: would be surprising if using abs didn't bring in all of the overloads
MC: that's Richard's argument
MC: move to ready

Proposed resolution:

This wording is relative to N3936.

  1. Modify 16.4.2.3[headers] p4 as indicated:

    Except as noted in Clauses 18 through 30 and Annex D, the contents of each headercname shall be the sameas that of the corresponding headername.h, as specified in the C standard library (1.2) or the C UnicodeTR, as appropriate, as if by inclusion. In the C++ standard library, however, the declarations (except fornames which are defined as macros in C) are within namespace scope (3.3.6) of the namespacestd. It isunspecified whether these names(including any overloads added in Clauses 18 through 30 and Annex D) are first declared within the global namespace scope and are then injected into namespacestd by explicit using-declarations (7.3.3).


[8]ページ先頭

©2009-2026 Movatter.jp