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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:35:45+00:00 2026-06-14T23:35:45+00:00

Consider the following C++11 program, and its result in GCC 4.7.2: int main() {

  • 0

Consider the following C++11 program, and its result in GCC 4.7.2:

int main()
{
   constexpr int i = 0;
   int* p = i;
}

// g++ -g -ggdb -Wall -Wextra -pedantic -std=c++11 t.cpp
// t.cpp: In function 'int main()':
// t.cpp:4:13: error: invalid conversion from 'int' to 'int*' [-fpermissive]
// t.cpp:4:9: warning: unused variable 'p' [-Wunused-variable]

According to the standard:

[C++11: 4.10/1]: A null pointer constant is an integral constant expression (5.19) prvalue of integer type that evaluates to zero [..]

5.19 is a mess and I’ve failed to parse it fully, but wouldn’t we expect i to satisfy this criterion and act as a null pointer constant, consequently requiring no explicit conversion to int* for the initialisation of p?

The compilation succeeds if I s/constexpr/const/ and compile with -ansi rather than -std=c++11.

  • 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-14T23:35:46+00:00Added an answer on June 14, 2026 at 11:35 pm

    [C++11: 5.19/3]: A literal constant expression is a prvalue core constant expression of literal type, but not pointer type. An integral constant expression is a literal constant expression of integral or unscoped enumeration type. [..]

    And:

    [C++11: 3.9/10]: A type is a literal type if it is:

    • a scalar type; or
    • a reference type; or
    • a class type (Clause 9) that has all of the following properties: [..]
    • an array of literal type.

    At this point, I can’t find a reason for that code to be non-compliant, so I suspect a GCC bug.

    However it may be a deliberate bug given that the passage you quoted out of 4.10 is proposed to be changed (active issue #903) so that this would in fact be non-compliant code.


    The compilation succeeds if I s/constexpr/const/ and compile with -ansi rather than -std=c++11.

    The definition of integral constant expression explicitly allowed this case in C++03:

    [C++03: 5.19/1]: [..] An integral constant-expression can involve only literals (2.13), enumerators, const variables or static data members of integral or enumeration types initialized with constant expressions (8.5), non-type template parameters of integral or enumeration types, and sizeof expressions. [..]

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

Sidebar

Related Questions

Consider following program: static void Main (string[] args) { int i; uint ui; i
Consider the following program: #include <stdio.h> int main(void) { return 0; } When i
Consider the following program. #include <stdio.h> int main() { int a[10]={0}; printf(%p %p\n, a,
Consider the following C program: int i = 0; int post_increment_i() { return i++;
Consider the following example program: next :: Int -> Int next i | 0
Consider the following short program: #include <type_traits> #include <iostream> using namespace std; template <typename
Consider the following C program, 'pause.c': void main() { pause(); } Compiling this on
Consider following source files 1.cpp #include <iostream> using namespace std; struct X { X()
Consider the following code: #include <stdio.h> #include <ctype.h> char* Mstrupr(char* szCad); int main() {
Consider the following program, which is obviously buggy: #include <cstdio> double test(int n) {

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.