Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mishandling of cv-qualification dropping in covariant return types #18233

Open
zygoloid mannequin opened this issue Nov 9, 2013 · 2 comments · May be fixed by #71696
Open

mishandling of cv-qualification dropping in covariant return types #18233

zygoloid mannequin opened this issue Nov 9, 2013 · 2 comments · May be fixed by #71696
Assignees
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Nov 9, 2013

Bugzilla Link 17859
Version trunk
OS Linux
CC @DougGregor

Extended Description

Clang accepts this ill-formed code:

typedef int X;
struct A { virtual const X *f(); };
struct B : A { virtual X *f(); };

Per 10.3/7, a covariant return type can only drop a cv-qualifier if it is a pointer or reference to class type.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
@Endilll Endilll added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Nov 6, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 6, 2023

@llvm/issue-subscribers-clang-frontend

Author: None (ec04fc15-fa35-46f2-80e1-5d271f2ef708)

| | | | --- | --- | | Bugzilla Link | [17859](https://llvm.org/bz17859) | | Version | trunk | | OS | Linux | | CC | @DougGregor |

Extended Description

Clang accepts this ill-formed code:

typedef int X;
struct A { virtual const X *f(); };
struct B : A { virtual X *f(); };

Per 10.3/7, a covariant return type can only drop a cv-qualifier if it is a pointer or reference to class type.

@ecnelises ecnelises self-assigned this Nov 8, 2023
@ecnelises
Copy link
Member

struct M {};
struct A { virtual const M *f(); };
struct B : A { virtual volatile M *f(); };

This should not be accepted but also acceptable to clang. GCC treats it as error.

As for motivating case:

struct A { virtual const int *f(); };
struct B : A { virtual int *f(); };

GCC emits warning instead of error, although it is ill-formed according to class.virtual:

The return type of an overriding function shall be either identical to the return type of the overridden function or covariant with the classes of the functions. If a function D​::​f overrides a function B​::​f, the return types of the functions are covariant if they satisfy the following criteria:

  • both are pointers to classes, both are lvalue references to classes, or both are rvalue references to classes
  • the class in the return type of B​::​f is the same class as the class in the return type of D​::​f, or is an unambiguous and accessible direct or indirect base class of the class in the return type of D​::​f
  • both pointers or references have the same cv-qualification and the class type in the return type of D​::​f has the same cv-qualification as or less cv-qualification than the class type in the return type of B​::​f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants