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

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

Closed
nabijaczleweli opened this issue Jan 17, 2024 · 4 comments
Labels
c clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate

Comments

@nabijaczleweli
Copy link

nabijaczleweli commented Jan 17, 2024

$ 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)

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Jan 17, 2024
@nabijaczleweli nabijaczleweli changed the title [Clang] errors with "conflicting types for" functions whose declarations only differ by return type constness [Clang] errors with "conflicting types for" function declarations which only differ by return type constness Jan 17, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed clang Clang issues not falling into any other category labels Jan 17, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 17, 2024

@llvm/issue-subscribers-clang-frontend

Author: наб (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
> &nbsp; &nbsp; &nbsp; &nbsp; 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&lt;remove_cv&lt;int&gt;&gt; qwe(void);
remove_atomic&lt;remove_cv&lt;const int&gt;&gt; qwe(void);

yielding

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

which is identical.

([Original report](https://101010.pl/@sebastian@jittr.click/111770387762063846))

@shafik
Copy link
Collaborator

shafik commented Jan 18, 2024

CC @AaronBallman this feel vaguely familiar but I can't find a similar issue.

@cor3ntin cor3ntin added the c label Jan 18, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 18, 2024

@llvm/issue-subscribers-c

Author: наб (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
> &nbsp; &nbsp; &nbsp; &nbsp; 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&lt;remove_cv&lt;int&gt;&gt; qwe(void);
remove_atomic&lt;remove_cv&lt;const int&gt;&gt; qwe(void);

yielding

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

which is identical.

([Original report](https://101010.pl/@sebastian@jittr.click/111770387762063846))

@AaronBallman AaronBallman added the duplicate Resolved as duplicate label Jan 18, 2024
@AaronBallman
Copy link
Collaborator

Duplicate of #39494

@AaronBallman AaronBallman marked this as a duplicate of #39494 Jan 18, 2024
@AaronBallman AaronBallman closed this as not planned Won't fix, can't repro, duplicate, stale Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

6 participants