public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108231] New: g++ mistakenly reports ambiguity between equivalent function declarations
@ 2022-12-27  7:30 bruno at clisp dot org
  2022-12-27  7:45 ` [Bug c++/108231] malloc attribute vs extern "C" in a namespace and global and using of one in the namespace in the global one pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: bruno at clisp dot org @ 2022-12-27  7:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231

            Bug ID: 108231
           Summary: g++ mistakenly reports ambiguity between equivalent
                    function declarations
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bruno at clisp dot org
  Target Milestone: ---

Created attachment 54156
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54156&action=edit
test case

The attached code, i1.cc, contains two equivalent function declarations for the
function 'free'. They are equivalent because they have the same signature and
both have "C" linkage.

In lines 9, 10, 12, 13, referencing the function 'free' works fine.

However, referencing it in line 17, as part of a
__attribute__ ((__malloc__ (free, 1)))
attribute, leads to an error "‘malloc’ attribute argument 1 is ambiguous".

I would expect no error, no warning.

How to reproduce:
$ g++ -S i1.cc
i1.cc:17:67: error: ‘malloc’ attribute argument 1 is ambiguous
   17 | __attribute__ ((__malloc__)) __attribute__ ((__malloc__ (free, 1)));
      |                                                                   ^
i1.cc:17:67: note: use a cast to the expected type to disambiguate

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/108231] malloc attribute vs extern "C" in a namespace and global and using of one in the namespace in the global one
  2022-12-27  7:30 [Bug c++/108231] New: g++ mistakenly reports ambiguity between equivalent function declarations bruno at clisp dot org
@ 2022-12-27  7:45 ` pinskia at gcc dot gnu.org
  2022-12-27  8:04 ` [Bug c++/108231] malloc attribute vs extern "C" in a namespace and global and using of one in the namespace in the global one and the builtin free pinskia at gcc dot gnu.org
  2022-12-27  8:11 ` [Bug c++/108231] malloc and cleanup attributes " pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-27  7:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
A little more reduced:
```
namespace g {
extern "C" void free(void *);
}
using g::free;
extern "C" void free (void *);

void foo1 (void *p) { free (p); }
void (*foo2) (void *) = free;
extern "C" {
void foo3 (void *p) { free (p); }
void (*foo4) (void *) = free;
}

extern "C" wchar_t * wcsdup (const wchar_t *s) 
__attribute__ ((__malloc__)) __attribute__ ((__malloc__ (free, 1)));
```

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/108231] malloc attribute vs extern "C" in a namespace and global and using of one in the namespace in the global one and the builtin free
  2022-12-27  7:30 [Bug c++/108231] New: g++ mistakenly reports ambiguity between equivalent function declarations bruno at clisp dot org
  2022-12-27  7:45 ` [Bug c++/108231] malloc attribute vs extern "C" in a namespace and global and using of one in the namespace in the global one pinskia at gcc dot gnu.org
@ 2022-12-27  8:04 ` pinskia at gcc dot gnu.org
  2022-12-27  8:11 ` [Bug c++/108231] malloc and cleanup attributes " pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-27  8:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
            Summary|malloc attribute vs extern  |malloc attribute vs extern
                   |"C" in a namespace and      |"C" in a namespace and
                   |global and using of one in  |global and using of one in
                   |the namespace in the global |the namespace in the global
                   |one                         |one and the builtin free
   Last reconfirmed|                            |2022-12-27

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The problem is related to that free is a builtin rather than the extern "C"
really.
-fno-builtin fixes the error too.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/108231] malloc and cleanup attributes vs extern "C" in a namespace and global and using of one in the namespace in the global one and the builtin free
  2022-12-27  7:30 [Bug c++/108231] New: g++ mistakenly reports ambiguity between equivalent function declarations bruno at clisp dot org
  2022-12-27  7:45 ` [Bug c++/108231] malloc attribute vs extern "C" in a namespace and global and using of one in the namespace in the global one pinskia at gcc dot gnu.org
  2022-12-27  8:04 ` [Bug c++/108231] malloc attribute vs extern "C" in a namespace and global and using of one in the namespace in the global one and the builtin free pinskia at gcc dot gnu.org
@ 2022-12-27  8:11 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-27  8:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|malloc attribute vs extern  |malloc and cleanup
                   |"C" in a namespace and      |attributes vs extern "C" in
                   |global and using of one in  |a namespace and global and
                   |the namespace in the global |using of one in the
                   |one and the builtin free    |namespace in the global one
                   |                            |and the builtin free

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is another example of the same issue but with cleanup attribute instead:
```
namespace std {
extern "C" int printf (const char*, ...);
}
using std::printf;
extern "C" int printf (const char*, ...);
void foo (const char *) { printf ("%s\n", __PRETTY_FUNCTION__); }

void bar () {
    const char a __attribute__ ((cleanup (printf))) = 0;
    printf ("%s calling ", __PRETTY_FUNCTION__);
    foo (&a);
    printf ("cleanup calling ");
}

int main ()
{
    bar ();
}
```

Note if you order swap the order of declarations of printf it works.
Same with free in the original testcase for malloc.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-27  8:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-27  7:30 [Bug c++/108231] New: g++ mistakenly reports ambiguity between equivalent function declarations bruno at clisp dot org
2022-12-27  7:45 ` [Bug c++/108231] malloc attribute vs extern "C" in a namespace and global and using of one in the namespace in the global one pinskia at gcc dot gnu.org
2022-12-27  8:04 ` [Bug c++/108231] malloc attribute vs extern "C" in a namespace and global and using of one in the namespace in the global one and the builtin free pinskia at gcc dot gnu.org
2022-12-27  8:11 ` [Bug c++/108231] malloc and cleanup attributes " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).