Skip to content

[Clang] errors with "conflicting types for" function declarations which only differ by return type constness #78499

Closed as not planned
@nabijaczleweli

Description

@nabijaczleweli
$ cat a.c
int qwe(void);
const int qwe(void);
$ cc -c a.c
a.c:2:11: error: conflicting types for 'qwe'
    2 | const int qwe(void);
      |           ^
a.c:1:5: note: previous declaration is here
    1 | int qwe(void);
      |     ^
1 error generated.
$ gcc -Wall -pedantic -c a.c
$ cc --version
Debian clang version 18.0.0 (++20231231112334+c7c912cff945-1~exp1~20231231112352.433)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /bin
$ gcc --version
gcc (Debian 12.2.0-14) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

(and the same with gcc 13.2.0-7)

In a Draft, 6.7.6.3 Function declarators, Semantics, 4, I see

If, in the declaration "T D1", D1 has the form
        D ( parameter-type-listopt ) attribute-specifier-sequenceopt
and the type specified for ident in the declaration "T D" is "derived-declarator-type-list T", then the type specified for ident is "derived-declarator-type-list function returning the unqualified, non-atomic version of T". The optional attribute specifier sequence appertains to the function type.

This appears to imply that the types for both declarations are processed thusly (pardon the C++-like syntax):

remove_atomic<remove_cv<int>> qwe(void);
remove_atomic<remove_cv<const int>> qwe(void);

yielding

int qwe(void);
int qwe(void);

which is identical.

(Original report)

Metadata

Metadata

Assignees

No one assigned

    Labels

    cclang:frontendLanguage frontend issues, e.g. anything involving "Sema"duplicateResolved as duplicate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions