Bug 79013

Summary: Inconsistent auto diagnostic in member declarations
Product: gcc Reporter: Jakub Jelinek <jakub>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal CC: dmalcolm, dodji, egallager, jakub, jason, lhyatt, webrown.cpp
Priority: P3 Keywords: accepts-invalid, diagnostic
Version: 7.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2017-08-21 00:00:00
Bug Depends on: 78693    
Bug Blocks: 79009    

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