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 8351621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:41:24+00:00 2026-06-09T08:41:24+00:00

I realized the following compiles fine in GCC 4.7: #include <memory> int main() {

  • 0

I realized the following compiles fine in GCC 4.7:

#include <memory>

int main() {
    std::shared_ptr<int> p;
    p = 0;
}

However, there is no assignment operator from int or from int*, and there is no implicit constructor from either int or int* either. There is a constructor from int*, but that one is explicit. I checked the standard library implementation and the constructor is indeed explicit, and no fishy assignment operators are in sight.

Is the program actually well-formed or is GCC messing with me?

  • 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-09T08:41:27+00:00Added an answer on June 9, 2026 at 8:41 am

    The reason this works is this short quote from the standard:

    §4.10 [conv.ptr] p1

    A null pointer constant is an integral constant expression (5.19) prvalue of integer type that evaluates to zero or a prvalue of type std::nullptr_t. […] A null pointer constant of integral type can be converted to a prvalue of type std::nullptr_t. […]

    And the fact that std::shared_ptr has an implicit constructor from std::nullptr_t:

    §20.7.2.2 [util.smartptr.shared] p1

    constexpr shared_ptr(nullptr_t) : shared_ptr() { }

    This also allows for oddities like this:

    #include <memory>
    
    void f(std::shared_ptr<int>){}
    
    int main(){
      f(42 - 42);
    }
    

    Live example.

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

Sidebar

Related Questions

I was debugging something in my code and realized that the following compiles NSMutableSet
I am compiling the following simple program with g++-4.6.1 --std=c++0x : #include <algorithm> struct
When answering another question, I realized that the following program does not quite do
I just realized that i may not be following best practices in regards to
I realized that ShowHeaderWhenEmpty only works in PostBacks. Is there any way to make
The following program terminates correctly: import System.Random randomList = mapM (\_->getStdRandom (randomR (0, 50000::Int)))
Given the following: // not a problem int i = 2, j = 3;
I'm looking for suggestions for the following issue, and I realize there is really
a) Shouldn’t the following assignment cause an error, since number 100 is a literal
I know there is a C++ version of this question, however I'm using standard

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.