Bug 1395185

Summary: Use of always_inline template functions fails to compile in precompiled header
Product: [Fedora] Fedora Reporter: James Legg <jlegg+rbz>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED EOL QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 24CC: davejohansen, jakub, jwakely, law, mpolacek
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-08 19:16:36 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description James Legg 2016-11-15 11:31:59 UTC
Description of problem:
Template functions with the always_inline attribute cannot be called from non-inline functions in a precompiled header without causing compilation of the precompiled header to fail.

Version-Release number of selected component (if applicable):
Arch: x86_64
Version: GCC 6.2.1
Release: 2.fc24

How reproducible:
Occurs every time.

Steps to Reproduce:
Compile the following code with g++ -x c++-header [filename]:
template <typename T> __attribute__((always_inline)) inline void f() {}
void g() {f<float>();}

Actual results:
$ g++ -x c++-header precompiled_header_bug.hh
precompiled_header_bug.hh: In function ‘void g()’:
precompiled_header_bug.hh:1:66: error: inlining failed in call to always_inline ‘void f() [with T = float]’: function body not available
 template <typename T> __attribute__((always_inline)) inline void f() {}
                                                                  ^
precompiled_header_bug.hh:2:21: note: called from here
 void g() {f<float>();}
                     ^
Expected results:
The compile should succeed. At least, if there is an error, it should not say "function body not available" and point to the function definition (as it has the function body right there).

Additional info:
The same code compiles successfully if compiled with -x c++ -c, and function f is inlined into g in this case.
It would also compile successfully if function g was declared inline. Normally, you wouldn't expect non-inline functions in a precompiled header, as using the precompiled header on multiple translation unit would create multiple symbol definitions. I found code which was using __attribute__((noinline)) __attribute__((weak)) on a function in a precompiled however. That function called an always_inline function, which called a templated always_inline function. The error message for that case does not refer to the original noinline weak function which was required to produce the error.

Comment 1 Fedora End Of Life 2017-07-25 23:53:53 UTC
This message is a reminder that Fedora 24 is nearing its end of life.
Approximately 2 (two) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 24. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '24'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version'
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not
able to fix it before Fedora 24 is end of life. If you would still like
to see this bug fixed and are able to reproduce it against a later version
of Fedora, you are encouraged  change the 'version' to a later Fedora
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.

Comment 2 Fedora End Of Life 2017-08-08 19:16:36 UTC
Fedora 24 changed to end-of-life (EOL) status on 2017-08-08. Fedora 24 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.