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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:21:38+00:00 2026-06-12T13:21:38+00:00

C++11 has the new override qualifier which can be applied to member functions to

  • 0

C++11 has the new override qualifier which can be applied to member functions to assert that they override a virtual function in the base class. C++11 also allows trailing return types so functions can be declared as auto f() -> return_type. When I combine both these features, I don’t know whether override goes before or after the ->.

For example, suppose we have the following base class:

struct Base {
    virtual auto f () const -> int = 0;
};

The two possibilities for a derived class are:

struct Derived : public Base {
    virtual auto f () const override -> int { return 0; } // Compiles on g++ 4.7.1
};

or

struct Derived : public Base {
    virtual auto f () const -> int override { return 0; } // Compiles on clang++ 4.0
};

g++ 4.7.1 compiles the first version but fails on the second with

test.cpp:6:30: error: expected ';' at end of member declaration
test.cpp:6:34: error: 'override' does not name a type

whereas clang++ 4.0 compiles the second one but fails on the first with

test.cpp:6:11: error: 'auto' return without trailing return type
  virtual auto f () const override -> int { return 0; }
          ^
test.cpp:6:3: error: only virtual member functions can be marked 'override'
  virtual auto f () const override -> int { return 0; }
  ^                       ~~~~~~~~
test.cpp:6:35: error: expected ';' at end of declaration list
  virtual auto f () const override -> int { return 0; }

Which of these compilers is actually doing the right thing according to the standard?

Edit: As Kerrek SB notes, this is a bug in gcc (Bugzilla link).

  • 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-12T13:21:39+00:00Added an answer on June 12, 2026 at 1:21 pm

    According to the standard, 8.4.1, a declarator for a function includes the trailing-return-type, and a class function definition contains “declarator virt-specifier-seqopt“. The second one, virt-specifier-seq, is one of final or override, so those come after the trailing return type. (I.e. Clang gets it right.)

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

Sidebar

Related Questions

My company has got a new project upcoming and i need software that can
I've read that Firefox 3.5 has a new feature in its parser ? Improvements
The new table has an auto-increment that I want to use for the data
I'm surprised that MS has implemented a new feature: Validation with INotifyDataErrorInfo I have
I am making a network application that has a chat function. On the chat
I have written an SWT UI which has a primary function of displaying text
I have Table which has SWT.CHECK style so I can remove checked items. I
The new Android 2.1 SDK (version 7) has a new class called SignalStrength: http://developer.android.com/reference/android/telephony/SignalStrength.html
A new colleague has just suggested using named HQL queries in Hibernate with annotations
C# has a cool new feature public Task<string> async f() { string r =

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.