List Info

Thread: static const data members violate the ODR




static const data members violate the ODR
country flaguser name
United States
2007-10-24 12:57:50
[MSVC 8.0] static const data members violate the ODR
----------------------------------------------------

                 Key: STDCXX-613
                 URL: http
s://issues.apache.org/jira/browse/STDCXX-613
             Project: C++ Standard Library
          Issue Type: Bug
          Components: External
         Environment: MSVC 7.0, 7.1, and 8.0
            Reporter: Martin Sebor


Copied from Rogue Wave Bugzilla: http://bugzilla.cvo.roguewave.com/show_bug.cgi?id=1744


The program below illustrates that a definition of each
static const integral data member of explicit
specializations of class templates that are initialized in
the body of the specialization is emitted by MSVC 7.0 in
each translation unit that references the member. This is,
of course, incorrect and leads to linker
errors.

$ cat t.cpp

template <class T>
struct S;

template <>
struct S<int>
{
 static const int i = 0;
};

#ifndef MAIN

const int S<int>::i;

#else

int main ()
{
 return S<int>::i;
}

#endif

$ cl -c -Fot.obj t.cpp && cl -c -DMAIN -Fomain.obj
t.cpp && cl main.obj t.obj
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version
13.00.9344.1 for 80x86
Copyright (C) Microsoft Corporation 1984-2001. All rights
reserved.
...
t.obj : error LNK2005: "public: static int const
S<int>::i" (?i?$SH2HB) already defined in
main.obj
main.exe : fatal error LNK1169: one or more multiply defined
symbols found

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue
online.


static const data members violate the ODR
country flaguser name
United States
2007-10-24 12:57:50
    [ https://issues.apache.org/jira/browse/
STDCXX-613?page=com.atlassian.jira.plugin.system.issuetabpan
els:comment-tabpanel#action_12537367 ] 

Martin Sebor commented on STDCXX-613:
-------------------------------------

Still broken in MSVC 8.0. See:
h
ttp://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.as
px?feedbackid=b9853206-740a-47e7-af09-b03b51934a97

The program below illustrates that a definition of each
static const
integral data member of explicit specializations of class
templates
that are initialized in the body of the specialization is
emitted by
MSVC 8.0 in each translation unit that references the
member. This is
incorrect and leads to linker errors.

$ cat t.cpp && cl -c -Fot.obj t.cpp && cl
-nologo -c -DMAIN
-Fomain.obj t.cpp && cl -nologo main.obj t.obj
template <class> struct S;
template <> struct S<int> { static const int i =
0; };

#ifndef MAIN
const int S<int>::i;
#else
int main () { return S<int>::i; }
#endif
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version
14.00.50727.42
for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

t.cpp
t.cpp
t.obj : error LNK2005: "public: static int const
S<int>::i"
(?i?$SH2HB) already defined in main.obj
main.exe : fatal error LNK1169: one or more multiply defined
symbols found

> [MSVC 8.0] static const data members violate the ODR
> ----------------------------------------------------
>
>                 Key: STDCXX-613
>                 URL: http
s://issues.apache.org/jira/browse/STDCXX-613
>             Project: C++ Standard Library
>          Issue Type: Bug
>          Components: External
>         Environment: MSVC 7.0, 7.1, and 8.0
>            Reporter: Martin Sebor
>
> Copied from Rogue Wave Bugzilla: http://bugzilla.cvo.roguewave.com/show_bug.cgi?id=1744

> The program below illustrates that a definition of each
static const integral data member of explicit
specializations of class templates that are initialized in
the body of the specialization is emitted by MSVC 7.0 in
each translation unit that references the member. This is,
of course, incorrect and leads to linker
> errors.
> $ cat t.cpp
> template <class T>
> struct S;
> template <>
> struct S<int>
> {
>  static const int i = 0;
> };
> #ifndef MAIN
> const int S<int>::i;
> #else
> int main ()
> {
>  return S<int>::i;
> }
> #endif
> $ cl -c -Fot.obj t.cpp && cl -c -DMAIN
-Fomain.obj t.cpp && cl main.obj t.obj
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version
13.00.9344.1 for 80x86
> Copyright (C) Microsoft Corporation 1984-2001. All
rights reserved.
> ...
> t.obj : error LNK2005: "public: static int const
S<int>::i" (?i?$SH2HB) already defined in
main.obj
> main.exe : fatal error LNK1169: one or more multiply
defined symbols found

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue
online.


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )