Bug 79013 - Inconsistent auto diagnostic in member declarations
Summary: Inconsistent auto diagnostic in member declarations
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, diagnostic
Depends on: 78693
Blocks: 79009
  Show dependency treegraph
 
Reported: 2017-01-06 11:01 UTC by Jakub Jelinek
Modified: 2021-02-26 04:23 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-08-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2017-01-06 11:01:00 UTC
+++ This bug was initially created as a clone of Bug #78693 +++

Multiple unresolved unclear issues from the above PR:

struct A
{
  auto foo(), bar();
};

auto A::foo() { return 1; }
auto A::bar() { return 2; }

Is this valid or not?  Both g++ and clang++ accept it.

[dcl.spec.auto]/7 says only:
"If the init-declarator-list contains more than one init-declarator, they shall all form declarations of variables."

which presumably doesn't apply to analogical member-declarator-list and member-declarator, but should it?

Another similar testcase:

struct B
{
  static auto const a = 5, foo(), bar();
};

auto const B::foo() { return 1; }
auto const B::bar() { return 2; }

Another issue:

struct C
{
  static auto const a = 5, b = 6L;
};

clang++ rejects this, g++ doesn't:

pr78693-5.C:3:10: error: 'auto' deduced as 'int' in declaration of 'a' and deduced as 'long' in declaration of 'b'
  static auto const a = 5, b = 6L;

The question is if [dcl.spec.auto]/7 further sentence:

"The type of each declared variable is determined by placeholder type deduction (7.1.7.4.1), and if the type that replaces the placeholder type is not the same in each deduction, the program is ill-formed."

applies just to the init-declarator-list or also to member-declarator-list.
Consistency and common sense would suggest that we should reject it like clang++ does, does the C++ standard need to be changed for that though?
Comment 1 Eric Gallager 2017-08-21 16:40:30 UTC
Confirmed, although changing from rejects-valid to accepts-invalid since g++ accepts all of the examples without printing any diagnostics.
Comment 2 Eric Gallager 2018-09-23 02:03:50 UTC
cc-ing diagnostics maintainers