Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8847779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:16:22+00:00 2026-06-14T12:16:22+00:00

Is the following code valid? struct B{ using X=int; }; struct D1:B{ using X=X;

  • 0

Is the following code valid?

struct B{ using X=int; };
struct D1:B{ using X=X; };   // (1)
struct D2:B{ typedef X X; }; // (2)

I would expect the point of declaration of D2::X to be between the two Xs in (2), but it seems both gcc 4.8 and clang 3.2 accept it.
Is this standard behavior ? References to the working draft/standard will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:16:23+00:00Added an answer on June 14, 2026 at 12:16 pm

    There was a debate on whether using X = X should pick up the being defined X or the X that potentially already was in scope. To avoid “unknown types” and to make it similar to typedef, it was ruled that the being-defined X is not visible in its to-be-assigned type expression (so rather than being similar to int x = x, it is similar to typedef x x;).

    Recall that typedef is just a normal declaration with the typedef keyword prepended. The first mentioning of X does not declare anything, it just says what type will be aliased. That’s the major difference with using X = X which could declare X earlier, if the committee decided that way.

    Note however your code is has effectively undefined behavior, because it violates a rule that has no required diagnostic. 3.3.7p1b2

    A name N used in a class S shall refer to the same declaration in its context and when re-evaluated in the completed scope of S. No diagnostic is required for a violation of this rule.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code yields an error error: ‘struct Foo’ is not a valid type
I would like to know if the following code are valid. The original intension
The following code is illegal: public struct MyStruct { public MyStruct(int a, int b)
I had come across the following code: typedef struct { double x; double y;
Needless to over explain. The following code is self-evident: struct X { X(int n){}
What is wrong with the following C++11 code: struct S { int a; float
Is the following code valid with C++ standard? It's strange that C::B would work
I have the following code. struct rectangle { int length; int breadth; }; int
The following code works fine: typedef struct node_s { void *data; struct node_s *next;
Empirically the following works (gcc and VC++), but is it valid and portable code?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.