c++/217: Compiler not following standards on templated constructor resolution

hubert@discreet.com hubert@discreet.com
Tue May 16 15:06:00 GMT 2000


>Number:         217
>Category:       c++
>Synopsis:       Compiler not following standards on templated constructor resolution
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          ice-on-legal-code
>Submitter-Id:   net
>Arrival-Date:   Tue May 16 15:06:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Patrick Hubert
>Release:        gcc version 2.96 20000410 (experimental)
>Organization:
>Environment:
Linux and SGI
>Description:
<See attached file>

"g++ -c bar.cxx" produces:

bar.cxx: In function `void func ()':
bar.cxx:21: no matching function for call to `Bar<int>::Bar (Bar<int>)'
bar.cxx:10: candidates are: Bar<X>::Bar (Bar<Y> &) [with Y = int, X =
bar.cxx:10: int]
bar.cxx:12:                 Bar<X>::Bar (Bar<X> &) [with X = int]

According to the standard, there should be no ambiguity:
One should try to resolve the call on non meta-templated
constructor first. Failing that, go on to meta-templated ones.

I do apologize for not being able to produce the exact
ISO/IEC standard that talks about that...

BTW: I tried on older version of egcs and got a different
error message (gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)):
gcc -c bar.cxx
bar.cxx: In function `void func()':
bar.cxx:21: warning: initialization of non-const reference `class Bar<int> &' from rvalue `Bar<int>'
bar.cxx:12: warning: in passing argument 1 of `Bar<int>::Bar<int>(Bar<int> &)'


>How-To-Repeat:
See description
>Fix:
instead of "Bar<int> f = Bar<int>();"
write "Bar<int> f( Bar<int>());"
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="bar.cxx"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="bar.cxx"

CnRlbXBsYXRlIDxjbGFzcyBYPgpjbGFzcyBCYXIgewpwdWJsaWM6CgogICBCYXIoKSB7fTsKICAg
fkJhcigpIHt9OwogICAKICAgdGVtcGxhdGUgPGNsYXNzIFk+CiAgIEJhciggQmFyPFk+ICZyICkg
e307CiAgIAogICBCYXIoIEJhciAmciApIHt9Owp9OwoKCgoKCnZvaWQgZnVuYygpCnsKICBCYXI8
aW50PiBmID0gQmFyPGludD4oKTsKfQoK


More information about the Gcc-prs mailing list