This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/34715] New: always_inline does not seem to force inlining when used only in the definition of a function in a namespace
- From: "lo at meep dot co dot uk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Jan 2008 18:07:13 -0000
- Subject: [Bug c++/34715] New: always_inline does not seem to force inlining when used only in the definition of a function in a namespace
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Snapshot gcc-4.3-20080104, gcc-4.3-20071109.
Test code below. When 'inline' modifier and 'always_inline' attribute are used
only in the definition of "min", inlining does not appear to happen (and no
error is output). When I add the modifier and attribute to the declaration of
"min", inlining does happen as expected.
Also: If I change X to a class, and min to a static function, inlining occurs
even if I mark only the declaration with 'inline' and 'always_inline'.
Note: I am assuming inlining hasn't happened due to the presence of the
following line in the assembly generated with the -S option:
call _ZN1X3minIiEERKT_S3_S3_
Apologies if that's not correct, or if I have misunderstood what's supposed to
happen with use of always_inline.
======================
PREPROCESSED SOURCE #1
======================
# 1 "y.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "y.cpp"
# 1 "try.h" 1
namespace X
{
template <class T>
const T& min(const T& a, const T& b);
}
template <class T>
inline __attribute__ ((always_inline)) const T& X::min(const T& a, const T& b)
{
return a < b ? a : b;
}
# 2 "y.cpp" 2
int main()
{
int a, b;
return X::min(a, b);
}
======================
PREPROCESSED SOURCE #2
======================
# 1 "y.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "y.cpp"
# 1 "try.h" 1
namespace X
{
template <class T>
inline __attribute__ ((always_inline)) const T& min(const T& a, const T& b);
}
template <class T>
inline __attribute__ ((always_inline)) const T& X::min(const T& a, const T& b)
{
return a < b ? a : b;
}
# 2 "y.cpp" 2
int main()
{
int a, b;
return X::min(a, b);
}
--
Summary: always_inline does not seem to force inlining when used
only in the definition of a function in a namespace
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: lo at meep dot co dot uk
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34715