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

  • SEARCH
  • Home
  • 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 7499341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:47:45+00:00 2026-05-29T19:47:45+00:00

Where in the C++ spec is this allowed? It’s cool. I want to know

  • 0

Where in the C++ spec is this allowed? It’s cool. I want to know how this is spec’d. I didn’t realize the spec allowed having a pointer to a undefined type.

class T;

int main(int argc, char* argv[])
{
   int x;
   T* p = reinterpret_cast<T*>(&x);
   return 0;
}
  • 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-05-29T19:47:46+00:00Added an answer on May 29, 2026 at 7:47 pm

    What you’re doing may be legal, but that depends on the real definition of class T, so we can’t know for sure based on the code you’ve shown.

    Starting with C++11 §3.9.2/3:

    Pointers to incomplete types are allowed although there are restrictions on what can be done with them.

    Those restrictions are listed in §3.2/4:

    A class type T must be complete if:

    • an object of type T is defined, or
    • a non-static class data member of type T is declared, or
    • T is used as the object type or array element type in a new-expression, or
    • an lvalue-to-rvalue conversion is applied to a glvalue referring to an object of type T, or
    • an expression is converted (either implicitly or explicitly) to type T, or
    • an expression that is not a null pointer constant, and has type other than void*, is converted to the type pointer to T or reference to T using an implicit conversion, a dynamic_cast or a static_cast, or
    • a class member access operator is applied to an expression of type T, or
    • the typeid operator or the sizeof operator is applied to an operand of type T, or
    • a function with a return type or argument type of type T is defined or called, or
    • a class with a base class of type T is defined, or
    • an lvalue of type T is assigned to, or
    • the type T is the subject of an alignof expression, or
    • an exception-declaration has type T, reference to T, or pointer to T.

    The 6th bullet appears pertinent here, as we can see in §5.2.10/7 that a reinterpret_cast between pointer types is defined in terms of static_cast:

    An object pointer can be explicitly converted to an object pointer of a different type. When a prvalue v of type “pointer to T1” is converted to the type “pointer to cv T2”, the result is static_cast<cv T2*>(static_cast<cv void*>(v)) if both T1 and T2 are standard-layout types and the alignment requirements of T2 are no stricter than those of T1, or if either type is void. Converting a prvalue of type “pointer to T1” to the type “pointer to T2” (where T1 and T2 are object types and where the alignment requirements of T2 are no stricter than those of T1) and back to its original type yields the original pointer value. The result of any other such pointer conversion is unspecified.

    But because reinterpret_cast static_casts to void* first, then to the real resulting pointer type, that 6th bullet doesn’t apply.

    So, so far you’re still in legal territory, despite T being an incomplete type. However, if it turns out that T is not a standard-layout type or has stricter alignment requirements than int, then the last sentence in §5.2.10/7 holds true and you’re invoking UB.

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

Sidebar

Related Questions

This is what my spec file looks like: spec/api/v1/projects_spec.rb require spec_helper describe /api/v1/projects, :type
I want to do something like this: @Stateless public class GreeterEjb { private final
How should I spec this class FlagsController def like flag = current_user.flags.find_or_initialize_by_flaggable_type_and_flaggable_id(params[:like_type], params[:like_id]) flag.kind
Is there a better way to write this spec? This works but I don't
I'm using this coffeescript code: in a spec file: index = new MeetingIndex(render: false,
I'm sure this information is available in the C# spec, but I thought I'd
The HTML spec shows the disabled and checked attributes for input elements like this:
Hi I have a file try.SPEC. This file contains a word Version: 1.0.0.1 .
I have this spec: it 'can parse armies with only section headers' do list
I ask this because typing spec returns this error.. ..ruby-1.9.2-head/lib/ruby/site_ruby/1.9.1/rubygems.rb:335:in `bin_path': can't find executable

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.