Bug 7221 - wrong linkage of typedef-named classes
Summary: wrong linkage of typedef-named classes
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.1
: P3 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords: link-failure, rejects-valid, xfail
: 29356 29873 37473 (view as bug list)
Depends on:
Blocks: 29843 41921
  Show dependency treegraph
 
Reported: 2002-07-06 09:26 UTC by Alexandre Oliva
Modified: 2022-12-26 08:36 UTC (History)
9 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.2.3, 4.9.0
Known to fail: 2.95.2, 4.8.5
Last reconfirmed: 2006-11-16 23:47:01


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexandre Oliva 2002-07-06 09:26:00 UTC
Given:

  typedef struct {
    void f();
  } S;

GCC will assume f has no linkage, because at the point of the declaration, the class is anonymous.

Details at http://gcc.gnu.org/ml/gcc-patches/2002-07/threads.html#00266

Release:
gcc-3.1

Environment:
3.2 as well as many (all?) older releases and newer snapshots
any

How-To-Repeat:
Testcase is g++.old-deja/g++.oliva/linkage1.C
Comment 1 Wolfgang Bangerth 2002-12-19 18:45:21 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed. Since 3.0, the symbols's name is at least
    correctly named S::f, but it still has internal linkage
    as of today.
Comment 2 Andrew Pinski 2006-10-05 14:25:12 UTC
*** Bug 29356 has been marked as a duplicate of this bug. ***
Comment 3 Geoff Keating 2006-11-16 23:47:01 UTC
See rejects-valid example in 29356.
Comment 4 Geoff Keating 2006-11-17 00:04:10 UTC
*** Bug 29873 has been marked as a duplicate of this bug. ***
Comment 5 Geoff Keating 2006-11-17 00:04:45 UTC
I mean, see rejects-valid example in bug 29873.
Comment 6 Andrew Pinski 2008-09-14 04:46:11 UTC
*** Bug 37473 has been marked as a duplicate of this bug. ***
Comment 7 Martin Sebor 2017-02-28 00:35:39 UTC
This works correctly in recent GCC versions.  Resolving as fixed.

$ cat t.C && gcc -S -Wall -Wextra -Wpedantic -o/dev/stdout t.C
typedef struct {
  void foo ();
} S;

void S::foo () { }
	.file	"t.C"
	.text
	.align 2
	.globl	_ZN1S3fooEv
	.type	_ZN1S3fooEv, @function
_ZN1S3fooEv:
.LFB0:
	.cfi_startproc
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	_ZN1S3fooEv, .-_ZN1S3fooEv
	.ident	"GCC: (GNU) 7.0.1 20170223 (experimental)"
	.section	.note.GNU-stack,"",@progbits