Skip to content

FR-025-017 10.3p6 [module.import] "static inline" used from header units #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wg21bot opened this issue Oct 23, 2022 · 6 comments
Closed
Labels
EWG Evolution has-paper rejected No consensus for a change.
Milestone

Comments

@wg21bot
Copy link
Collaborator

wg21bot commented Oct 23, 2022

After implementation and deployment of this rule and the paragraphs (6.3) referenced in the note, it turns out that functions defined “static inline” in headers (often shared between C and C++) are more common than realized and the restriction of not being them to refer such names/entities constitutes a huge practical usability problem.

Permit uses of names/entities defined as “static inline” in header units, and problem that each translation unit that odr-uses those names as a TU-local copy of those definitions, which corresponds to the behaviour if the header units had been #included.

@wg21bot wg21bot added the EWG Evolution label Oct 23, 2022
@wg21bot wg21bot added this to the CD C++23 milestone Oct 23, 2022
@wg21bot wg21bot changed the title FR 10.3 [module.import] "static inline" used from header units FR 10.3p6 [module.import] "static inline" used from header units Oct 23, 2022
@jensmaurer jensmaurer changed the title FR 10.3p6 [module.import] "static inline" used from header units FR-025-017 10.3p6 [module.import] "static inline" used from header units Nov 3, 2022
@BengtGustafsson
Copy link

Do we have any statistics on whether making functions static inline was ever a conscious choice or just mistakes? To me it seems unlikely that anyone would rely on the addresses of the generated static functions differ. Maybe someone has made a try to increase the cache locality by duplicating the code.

If we can accept that relying on the addresses being different is deprecated header units could allow such declarations but override the actual code duplication. Possibly taking the address of such a function could be made illegal to catch any cases where code relies on address differences but this would cause compilation of valid code taking the address for valid purposes to fail, though.

@jfbastien
Copy link
Collaborator

Paper: cplusplus/papers#1356

@jfbastien
Copy link
Collaborator

Discussed today, exploring these options:

header <time.h>

struct time_t {/* ... */};

static inline time_t time(time_t *);

Translation unit #1

module;
#include <time.h>                   // With or without include translation
export module A;
static void f() {}
inline void it() { f(); }           // error: is an exposure of f
static inline void its() { f(); }   // OK

void ff() { time(nullptr); }        // OK
inline void iff() { time(nullptr); }// Potential UB: ODR violation.

namespace A {
  export using time = ::time;              // Potential UB: ODR violation.
  export using f = ::f;                    // error: exposure of f
}

Translation unit #2
module;
#include <time.h>
export module B;
namespace B {
  export using time = ::time;
}

TU #3

import A;
import B;

/*
 Don't need to say anything about which `time` you get as we already have
 [module.import]/5 that says you can end up with multiple copies of `time`.
 
 If a (possibly instantiated) declaration of, or a deduction guide for, a non-TU-local entity in a module interface unit (outside the private-module-fragment, if any) or module partition ([module.unit]) is an exposure <INSERT HERE>, the program is ill-formed. Such a declaration in any other context is deprecated ([depr.local]).

 that names a TU-local entitiy in the purview of a module.
 
 Also say that: It's unspecified which entity you get for TU-local entities named by an exposure.
 
 Alternative: Linkage promotion!!!!
 p1498r1
 p1347r1
 p1395r0
 
 Any reference in a module to a TU-local entitiy that is an exposure creates a copy of that entity with external linkage.
 */

Implementors will discuss within the next month, organize SG2 telecons, and come back with a single suggested resolution by the February 2023 meeting.

@erichkeane
Copy link

This was discussed in EWG in the February 7th, 2023 Morning Session in Issaquah. The following poll was taken:

EWG encourages further work in the direction of the presented proposal for FR-025-017, and want(s) to see this again with wording.

SF F N A SA
9 10 2 0 0

Result: Consensus

@jfbastien
Copy link
Collaborator

Poll: accepts D2808r0 as a resolution to FR-025-017 for C++23, make it a DR on prior versions.

SF F N A SA
0 4 4 7 1

Result: No Consensus

Any objection to unanimous consent to rejecting FR-025-017 for C++23?
None.

@jfbastien jfbastien added the rejected No consensus for a change. label Feb 10, 2023
@jensmaurer
Copy link
Member

Rejected. No consensus for a change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
EWG Evolution has-paper rejected No consensus for a change.
Projects
None yet
Development

No branches or pull requests

5 participants