This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53926] New: g++ fails to compile valid template code with casting to QVariant and back
- From: "a.matveyakin at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 11 Jul 2012 11:30:49 +0000
- Subject: [Bug c++/53926] New: g++ fails to compile valid template code with casting to QVariant and back
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53926
Bug #: 53926
Summary: g++ fails to compile valid template code with casting
to QVariant and back
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: a.matveyakin@gmail.com
Trying to compile the following code:
#include <QtCore/QSettings>
template <typename T>
void bug (const T& default_value)
{
QSettings settings;
settings.value ("foo", default_value).value <T> ();
}
results in compilation failure:
$ gcc -I/usr/include/qt4 -c gcc-bug.cpp
gcc-bug.cpp: In function âvoid bug(const T&)â:
gcc-bug.cpp:7:49: error: expected primary-expression before â>â token
gcc-bug.cpp:7:52: error: expected primary-expression before â)â token
The error can be reproduced in a small code piece without any includes:
class Variant
{
public:
Variant (int) { }
template <typename T>
T value () const { return T (); }
};
template <typename T>
Variant get_variant (const T& x)
{
return Variant (x);
}
template <typename T>
void bug (const T& x)
{
get_variant (x).value <T> ();
}
$ gcc -I/usr/include/qt4 -c gcc-bug.cpp
gcc-bug.cpp: In function âvoid bug(const T&)â:
gcc-bug.cpp:19:27: error: expected primary-expression before â>â token
gcc-bug.cpp:19:30: error: expected primary-expression before â)â token
Splitting the line
get_variant (x).value <T> ();
into
Variant tmp = get_variant (x);
tmp.value <T> ();
eliminates the error.
The error is reproducible in 4.2.4, 4.5.1, 4.6.3 and 4.8.1 prerelease versions.
ICC & MSVC compile these examples without errors or warnings.