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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:43:00+00:00 2026-05-26T00:43:00+00:00

Here is a piece of code: class Class { static constexpr int getBug(); };

  • 0

Here is a piece of code:

class Class
{
    static constexpr int getBug();
};

constexpr int Class::getBug()
{
    return 0;
}

What I basically do is declaring a static constepxr method in class declaration, then I implement it.

The original code was split in two file, and contained more methods / attributes which have been stripped, leaving only the required code.

When I compile the code I get the following error from GCC 4.6.0 :

Class.cpp:6:29: internal compiler error: in merge_types, at cp/typeck.c:825
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
  1. Is this really a bug?

  2. In that case, what must I provide my report with?


I’ve tested the code on an online C++0x compiler and get the following error:

prog.cpp:3:33: error: the 'constexpr' specifier cannot be used in a function declaration that is not a definition
prog.cpp:6:29: error: a constexpr function cannot be defined outside of its class

This compiler uses GCC 4.5.1.
It let me know that my code is ill-formed, but introduce more question:

  1. Why does GCC 4.5.1 give an error and GCC 4.6.0 report a bug?

After writing the last paragraph, I tested back on GCC 4.6.0 stripping the static keyword and the separate implementation compiles without any warning!

  1. Why do two compiler of the same family behave so differently?

I know that constexpr methods should avoid any statement different to return, which may explain the GCC 4.5.1 error reporting.
As my method uses macro condition to return the good (constant) value, it takes a couple of line which explains why I want to use separated implementation (in addition to the usual recommendation).


My configuration:

Mac OS X.7
GCC 4.6.0
Target: x86_64-apple-darwin10.7.0
Configured with: ./configure
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.7.0' '-v' '-save-temps' '-std=c++0x' '-c' '-shared-libgcc' '-mtune=core2'
  • 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-26T00:43:01+00:00Added an answer on May 26, 2026 at 12:43 am

    This is because constexpr is a new feature of the language, and according to the C++0x Support in GCC page, the support for this feature was first added to GCC in 4.6. My suspicion is that it is in fact a bug in the compiler, that could be fixed in 4.6.1 or later.

    GCC 4.5.2 generates an error because the feature isn’t yet available in that version. In fact, if you were to check the standard library headers for 4.5.2, you would see that all of the constexpr methods (as dictated by the standard) say something like ‘Needs constexpr’.

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

Sidebar

Related Questions

I have a piece of code like this: Class Program { static StreamReader sr
I'm having some problems with this piece of code. I've included a class declaration
Allright, here it goes a good piece of bad code: public class Log :
Here's a piece of code to take a string (either NSString or NSAttributedString) input
Here is an interesting piece of code that my fellow team members were just
I have a piece of code here that i really could use some help
Let's say we have the following piece of code: public class Event { }
here's a runnable piece of code that shows what my problem is. I've got
Here is my code, which takes two version identifiers in the form 1, 5,
I was perplexed after executing this piece of code, where strings seems to behave

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.