This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/23542] New: Warn template instantiation calling static functions
- From: "veksler at il dot ibm dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Aug 2005 06:47:24 -0000
- Subject: [Bug c++/23542] New: Warn template instantiation calling static functions
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
As described in the thread "Should template dependent lookup find static
functions?" :
http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/d6d9a5f3e12ccf80/7038bb2e4c75e190#7038bb2e4c75e190
I'll give the example again:
---- begin example ----
class inner_t { };
template <class T>
struct outer_t { T m_elem; };
template <class T>
void examine(const outer_t<T> & data)
{
// Finding the static (or anon-namespace) function may lead
// to undefined behavior (when it happens in multiple translation
// units).
access(data.m_elem);
}
// NOTE: this is static! GCC finds it as a dependent name from examine.
// This *may* lead to undefined behavior.
static void access(const inner_t & ) {}
int main()
{
outer_t<inner_t> instance;
examine(instance);
}
--- end example ---
gcc-3.4.3 and gcc-4.0.0 accept this without a warning.
(-W -Wall -O{0,1,2} give no warning).
The problem is that if both static function and the template
function are in a header file, then the behavior is undefined,
yet the compiler has to accept it (it may issue a warning).
Of course, GCC may implement an extension and document it,
such that it is no longer undefined for GCC (e.g. make it
defined as long as having the same static function).
The same problem happens when `static' is replaced
with `namespace {'.
--
Summary: Warn template instantiation calling static functions
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: veksler at il dot ibm dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23542