Skip to content

No namespace awareness of static template fields #8456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
llvmbot opened this issue Sep 5, 2010 · 5 comments
Closed

No namespace awareness of static template fields #8456

llvmbot opened this issue Sep 5, 2010 · 5 comments
Labels
bugzilla Issues migrated from bugzilla c++

Comments

@llvmbot
Copy link
Member

llvmbot commented Sep 5, 2010

Bugzilla Link 8084
Resolution FIXED
Resolved on Sep 12, 2010 00:25
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@efriedma-quic

Extended Description

cat foo.cxx
namespace F {
template struct Foo {
static A *field;
};
}

using namespace F;
struct Bar : Foo {};
template <> Bar* Foo::field = 0;

clang++ -fsyntax-only foo.cxx
foo.cxx:9:28: error: static data member specialization of 'field' must originally be declared in namespace 'F'
template <> Bar* Foo::field = 0;
^
foo.cxx:3:19: note: explicitly specialized declaration is here
static A *field;

================================================================
system: Linux 2.6.32-24-generic amd64 Ubuntu 10.04
clang version 2.8 (trunk 113084)
Target: x86_64-unknown-linux-gnu
Thread model: posix

@llvmbot
Copy link
Member Author

llvmbot commented Sep 5, 2010

works:
namespace F {
template struct Foo {
static A *field;
};
}

namespace F {
struct Bar : Foo {};
template <> Bar* Foo::field = 0;
}


same error:
namespace F {
template struct Foo {
static A *field;
};
}

struct Bar : F::Foo {};
template <> Bar* F::Foo::field = 0;

@efriedma-quic
Copy link
Collaborator

I'm pretty sure gcc is wrongly accepting this... where does the testcase come from?

@llvmbot
Copy link
Member Author

llvmbot commented Sep 6, 2010

These code snippets are the short version of the problem when I compile ogre3d. Here the original problem in ogre3d 1.7.1 (http://www.ogre3d.org/):

File: ogreSrc/OgreMain/include/OgreSingleton.h
...
namespace Ogre {
template class Singleton {
protected:
static T* ms_Singleton;
};
}

File: ogreSrc/Samples/DeferredShading/include/SharedData.h
...
class SharedData : public Ogre::Singleton { ... }

File: ogreSrc/Samples/DeferredShading/src/DeferredShadingDemo.cpp
...
using namespace Ogre;
template<> SharedData* Singleton::ms_Singleton = 0;

In my opinion this c++ code is valid.

@DougGregor
Copy link
Contributor

Clang is technically correct, per C++98 [temp.expl.spec]p2:

An explicit specialization of a member function, member class or static data member of a class template shall be declared in the namespace of which the class template is a member.

C++0x actually loosens this restriction to allow the code in question, so it's probably reasonable to downgrade this to an "extension warning" in C++98/03 mode. Besides, GCC doesn't diagnose it and EDG only diagnoses it in strict mode, so giving an error is rather harsh.

@DougGregor
Copy link
Contributor

When the code obeys the C++0x semantics but not the C++98/03 semantics (as the examples described here do), I've downgraded the error to a warning in Clang r113718.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
Michael137 pushed a commit to Michael137/llvm-project that referenced this issue Apr 2, 2024
[cherry-pick stable/20230725] Revert "[ClangScanDeps] Fix cas dependency scanning test after D159064"
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++
Projects
None yet
Development

No branches or pull requests

3 participants