Skip to content
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

[basic.def.odr] Greatly expand example 6 #6483

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Eisenwave
Copy link
Contributor

image

The ODR is fairly complex, and deserving of examples which elaborate on intent and behavior in more detail. Firstly, the new style interleaves explanations and code blocks, which is necessary due to the scale of the example.

First Addition

static int local = 0; // OK
inline int a(int = local) { // OK
  return 0;
}
inline int b = a(0); // OK
inline int c = a(); // IFNDR

This example demonstrates three important mechanisms:

  • semantic differences can violate the ODR, even if the syntax is the same in every TU
  • using entities with internal linkage is dangerous
  • default arguments in the parameter list are not subject to the requirements of the ODR
  • however, uses of such default arguments are subject to the ODR

This part is much simpler than the subsequent part involving lambda-expressions, and establishes the knowledge necessary to understand the second part.

Second Addition

The new (third) part of the example is as follows:

inline decltype([]{}) u = {}; // IFNDR
inline auto v = []{}; // OK
inline auto w = decltype([]{}){}; // OK

This demonstrates that:

  • using lambda expressions in declarations is a major footgun, and can violate the ODR in a more direct way
  • lambda-expressions can appear in a definition, even without being contained within a block scope, and this doesn't violate the ODR

This part of the example is actually related to implementation divergence: https://godbolt.org/z/749Tf53hG / llvm/llvm-project#64811.

@jensmaurer
Copy link
Member

This is mostly CWG2782. I want that to land before applying additional editorial work, to avoid editing conflicts.

@tkoeppe tkoeppe added the cwg Issue must be reviewed by CWG. label Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cwg Issue must be reviewed by CWG.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants