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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:37:38+00:00 2026-06-15T07:37:38+00:00

I was creating a function in Visual Studio 2012 to check if an item

  • 0

I was creating a function in Visual Studio 2012 to check if an item was the default and went to call it default(). However, I noticed that when I finished and waited a couple of seconds, the name was no longer bolded and no Intellisense errors were shown. Intrigued, I tried it out:

void default(){}

int main() {
    default();
}

This code works on Visual Studio 2012 with both the regular compiler and the November 2012 CTP one, but does not compile on GCC 4.7.2 or on http://llvm.org/demo. I realize that default is used for both switches and for = default on some class members. VS2012 does not support the latter, but it obviously supports the former, and it does indeed complain if I change the function name to delete, nullptr, or switch, or case.

On GCC, I get this:

error: expected unqualified-id before ‘default’
In function ‘int main()’:
error: case label not within a switch statement
error: expected ‘:’ before ‘(‘ token
error: expected primary-expression before ‘)’ token

Clang gives me this:

error: expected unqualified-id
void default(){}
……..^

I’m obviously changing the name of it now, but is VS wrong in accepting this, or did it perhaps change specifically with the = default and = delete addition to the language? If VS doesn’t support that, and that’s the cause of the program being wrong, I could see why it accepts it.

I found this in the spec (C++11 § 6.1/2):

Case labels and default labels shall occur only in switch statements.

Since it is not being used as a label, with the colon following it, I guess it could be argued that it’s allowed, but then why would case compile? I’m guessing there’s something more specific to function names, but I couldn’t find it.

Are you allowed to name a function default(), and does the rule differ between C++03, and 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-15T07:37:39+00:00Added an answer on June 15, 2026 at 7:37 am

    The default identifier is reserved for use as a keyword:

    The identifiers shown in Table 4 are reserved for use as keywords (that is, they are unconditionally treated as keywords in phase 7) except in an attribute-token

    Table 4† contains, among all other keywords, default. VC++ is wrong to accept an identifier of default outside of an attribute-token, and a function name is not an attribute-token..

    † It’s Table 4 in C++11, but Table 3 in C++98 and 03. Nonetheless, they all contain default.

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

Sidebar

Related Questions

I 'm writing a Visual Studio extension where I'm creating line adornments that need
I am creating a function that I would like to generate random strings from
I'm looking for some Javascript jedi-master to assist in creating a function that adds
I'm creating an initialising function for the class 'Room', and found that the program
im creating a dll in MS Visual Studio 2010 Express which loads a binary
Im creating an unmanaged DLL in Visual Studio 2010. In order to test my
I am creating an ATL 8.0 based ActiveX control in C++ using Visual Studio
I'm creating an Addin to be used in Outlook 2010 using Visual Studio 2008
I am having trouble using the XSLT 1.0 function library (since .NET/Visual Studio doesn't
I have a Visual Studio 2008 C++ project where I'm creating a DLL with

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.