Where does the rule in the standard specify that a function with a trailing-return-type whose return type contains a placeholder type should be `auto`

jack X
auto* fun()->int*{}
int main(){
}

This snippet is rejected by both Clang and GCC, and they report an error, which is

'fun' function with trailing return type has 'auto*' as its type rather than plain 'auto'

However, I haven't found any rule that forbids this usage in the standard. The only relevant rule that I feel correspond is the following:

In a declaration T D where D has the form

 D1 ( parameter-declaration-clause ) cv-qualifier-seq opt
    ref-qualifier opt noexcept-specifier opt attribute-specifier-seq opt trailing-return-type

and the type of the contained declarator-id in the declaration T D1 is “derived-declarator-type-list T”, T shall be the single type-specifier auto.

However, according to dcl.meaning#3, which says:

Thus, a declaration of a particular identifier has the form

T D

where T is of the form attribute-specifier-seqopt decl-specifier-seq and D is a declarator.

Hence, back to this example, T is auto and the declarator is *fun()->int*. So, T here is a single type-specifier auto, the declaration does not violate any rule. Why do GCC and Clang both reject the valid code? If I miss the rule that forbids this usage in the standard, what's the rule?

T.C.

It's the grammar. This was core issue 681.

declarator:
  ptr-declarator
  noptr-declarator parameters-and-qualifiers trailing-return-type

ptr-declarator:
  noptr-declarator
  ptr-operator ptr-declarator

noptr-declarator:
  declarator-id attribute-specifier-seq_opt
  noptr-declarator parameters-and-qualifiers
  noptr-declarator [ constant-expression_opt ] attribute-specifier-seq_opt
  ( ptr-declarator )

*f () -> whatever is not a valid declarator; the grammar disallows a ptr-declarator at that position. (It follows that it is unsurprising that the rules for interpreting declarators don't provide for this occasion - as discussed in the comments.)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Where does the rule in the standard specify that a function with a trailing-return-type whose return type contains a placeholder type should be `auto`

From Dev

Does a placeholder in a trailing-return-type override an initial placeholder?

From Dev

Specialize auto trailing return type

From Dev

Is there an intention behind the auto keyword in trailing return type function syntax?

From Dev

Should main with trailing return type be avoided?

From Dev

Should main with trailing return type be avoided?

From Dev

Trailing return type and rvalues

From Dev

Trailing return type array

From Dev

What does a function whose 'return type' is a tag do?

From Dev

Using a function pointer with a trailing return type

From Dev

Specialize function template with decltype trailing return type

From Dev

Specialize function template with decltype trailing return type

From Dev

Bool type return rule

From Dev

Does the standard have any normative wording for a function with no return type?

From Dev

In Scala is there a way to specify that the return type should match the type of the method caller?

From Dev

In Scala is there a way to specify that the return type should match the type of the method caller?

From Java

Specify return type in TypeScript arrow function

From Dev

Type-id ambiguity in trailing return type

From Dev

Why can't auto be return type of a function?

From Dev

Should std::function assignment ignore return type?

From Dev

What should be the return type of function that is run async

From Dev

Function should return type of a not-null parameter

From Dev

Trailing return type issue when using restricted function

From Dev

How do I return by value for an "auto" return type function

From Dev

Specify the return content type of a Controller

From Dev

GCC attribute warning with trailing return type when return type is a class

From Java

How to specify "nullable" return type with type hints

From Dev

How to specify "own type" as return type in Kotlin

From Dev

How to specify "nullable" return type with type hints

Related Related

  1. 1

    Where does the rule in the standard specify that a function with a trailing-return-type whose return type contains a placeholder type should be `auto`

  2. 2

    Does a placeholder in a trailing-return-type override an initial placeholder?

  3. 3

    Specialize auto trailing return type

  4. 4

    Is there an intention behind the auto keyword in trailing return type function syntax?

  5. 5

    Should main with trailing return type be avoided?

  6. 6

    Should main with trailing return type be avoided?

  7. 7

    Trailing return type and rvalues

  8. 8

    Trailing return type array

  9. 9

    What does a function whose 'return type' is a tag do?

  10. 10

    Using a function pointer with a trailing return type

  11. 11

    Specialize function template with decltype trailing return type

  12. 12

    Specialize function template with decltype trailing return type

  13. 13

    Bool type return rule

  14. 14

    Does the standard have any normative wording for a function with no return type?

  15. 15

    In Scala is there a way to specify that the return type should match the type of the method caller?

  16. 16

    In Scala is there a way to specify that the return type should match the type of the method caller?

  17. 17

    Specify return type in TypeScript arrow function

  18. 18

    Type-id ambiguity in trailing return type

  19. 19

    Why can't auto be return type of a function?

  20. 20

    Should std::function assignment ignore return type?

  21. 21

    What should be the return type of function that is run async

  22. 22

    Function should return type of a not-null parameter

  23. 23

    Trailing return type issue when using restricted function

  24. 24

    How do I return by value for an "auto" return type function

  25. 25

    Specify the return content type of a Controller

  26. 26

    GCC attribute warning with trailing return type when return type is a class

  27. 27

    How to specify "nullable" return type with type hints

  28. 28

    How to specify "own type" as return type in Kotlin

  29. 29

    How to specify "nullable" return type with type hints

HotTag

Archive