public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/42840]  New: const-ref argument in a variadic template arglist is mishandled
@ 2010-01-22  3:30 navin dot kumar at gmail dot com
  2010-01-22  3:33 ` [Bug c++/42840] " navin dot kumar at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: navin dot kumar at gmail dot com @ 2010-01-22  3:30 UTC (permalink / raw)
  To: gcc-bugs

When a static-const primitive is passed as a const-ref argument to function
with a variadic template arglist, GCC generates code that references the
static-const primitive, and optimizes away the static-const primitive,
resulting in a "undefined reference" linker error.

/* Start of Example */
class Foo {
public:
    template <typename... T>
    static void foo(const T&... blah) { }
};

class Test {
public:
    static const int tmp = 1;
};

int main(int argc, char** argv) {
    Foo::foo(Test::tmp); // THIS COMPILES BUT LINKER FAILS
    //Foo::foo(static_cast<int>(Test::tmp)); // THIS COMPILES AND LINKS FINE
}
/* END OF EXAMPLE */

LINKER ERROR:
/tmp/ccfV1opu.o: In function `main':
tmp.cc:(.text+0x10): undefined reference to `Test::tmp'
collect2: ld returned 1 exit status

Since static cast of the static-const int primitive to an int fixes the
problem, it's clear that GCC is somehow mishandling how it optimizes away
Test::tmp even though it's being used as a const int& in Foo::foo(...)


-- 
           Summary: const-ref argument in a variadic template arglist is
                    mishandled
           Product: gcc
           Version: 4.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: navin dot kumar at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42840


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

* [Bug c++/42840] const-ref argument in a variadic template arglist is mishandled
  2010-01-22  3:30 [Bug c++/42840] New: const-ref argument in a variadic template arglist is mishandled navin dot kumar at gmail dot com
@ 2010-01-22  3:33 ` navin dot kumar at gmail dot com
  2010-01-22  3:39 ` navin dot kumar at gmail dot com
  2010-01-22 12:01 ` jwakely dot gcc at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: navin dot kumar at gmail dot com @ 2010-01-22  3:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from navin dot kumar at gmail dot com  2010-01-22 03:32 -------
Created an attachment (id=19686)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19686&action=view)
example of code that generates linker error

compiled with ver 4.3.4 g++ and args -std=c++0x


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42840


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

* [Bug c++/42840] const-ref argument in a variadic template arglist is mishandled
  2010-01-22  3:30 [Bug c++/42840] New: const-ref argument in a variadic template arglist is mishandled navin dot kumar at gmail dot com
  2010-01-22  3:33 ` [Bug c++/42840] " navin dot kumar at gmail dot com
@ 2010-01-22  3:39 ` navin dot kumar at gmail dot com
  2010-01-22 12:01 ` jwakely dot gcc at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: navin dot kumar at gmail dot com @ 2010-01-22  3:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from navin dot kumar at gmail dot com  2010-01-22 03:39 -------
Ignore.  Close bug.

Found the issue here:
http://hellewell.homeip.net/phillip/blogs/index.php?entry=entry060314-000000


-- 

navin dot kumar at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42840


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

* [Bug c++/42840] const-ref argument in a variadic template arglist is mishandled
  2010-01-22  3:30 [Bug c++/42840] New: const-ref argument in a variadic template arglist is mishandled navin dot kumar at gmail dot com
  2010-01-22  3:33 ` [Bug c++/42840] " navin dot kumar at gmail dot com
  2010-01-22  3:39 ` navin dot kumar at gmail dot com
@ 2010-01-22 12:01 ` jwakely dot gcc at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2010-01-22 12:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jwakely dot gcc at gmail dot com  2010-01-22 12:00 -------
N.B. duplicate of Bug 14404


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42840


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

end of thread, other threads:[~2010-01-22 12:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-22  3:30 [Bug c++/42840] New: const-ref argument in a variadic template arglist is mishandled navin dot kumar at gmail dot com
2010-01-22  3:33 ` [Bug c++/42840] " navin dot kumar at gmail dot com
2010-01-22  3:39 ` navin dot kumar at gmail dot com
2010-01-22 12:01 ` jwakely dot gcc at gmail dot com

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