Skip to content
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

GCC13 build error: possibly dangling reference to a temporary #65449

Closed
tim110011 opened this issue May 3, 2023 · 2 comments
Closed

GCC13 build error: possibly dangling reference to a temporary #65449

tim110011 opened this issue May 3, 2023 · 2 comments
Labels
(S1 - Need confirmation) Report waiting on confirmation of reproducibility

Comments

@tim110011
Copy link

Describe the bug

On fedora 38, build CDDA using GCC13 failed, clang works.
Make flags:
-j8
CLANG=0
CCACHE=1
RELEASE=1
LTO=1
TILES=1
SOUND=1
LOCALIZE=1
LANGUAGES=zh_CN
DYNAMIC_LINKING=0
RUNTESTS=0
-march=native

Attach save file

src/action.cpp: In function ‘bool can_examine_at(const tripoint&, bool)’:
src/action.cpp:673:19: 错误:possibly dangling reference to a temporary [-Werror=dangling-reference]
673 | const furn_t &xfurn_t = here.furn( p ).obj();
| ^~~~~~~
src/action.cpp:673:47: 附注:the temporary was destroyed at the end of the full expression ‘(& here)->map::furn((* & p)).int_id<furn_t>::obj()’
673 | const furn_t &xfurn_t = here.furn( p ).obj();
| ~~~~~~~~~~~~~~~~~~^~
src/action.cpp:674:18: 错误:possibly dangling reference to a temporary [-Werror=dangling-reference]
674 | const ter_t &xter_t = here.ter( p ).obj();
| ^~~~~~
src/action.cpp:674:44: 附注:the temporary was destroyed at the end of the full expression ‘(& here)->map::ter((* & p)).int_id<ter_t>::obj()’
674 | const ter_t &xter_t = here.ter( p ).obj();
| ~~~~~~~~~~~~~~~~~^~
在文件作用域:
cc1plus: 附注:unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
cc1plus:所有的警告都被当作是错误
make: *** [Makefile:975: obj/tiles/action.o] Error 1
make: *** 正在等待未完成的任务....
src/activity_item_handling.cpp: In function ‘activity_reason_info can_do_activity_there(const activity_id&, Character&, const tripoint_bub_ms&, int)’:
src/activity_item_handling.cpp:1344:31: 错误:possibly dangling reference to a temporary [-Werror=dangling-reference]
1344 | const recipe &r = recipe_dictionary::get_uncraft( ( i.typeId() == itype_disassembly ) ?
| ^
src/activity_item_handling.cpp:1344:65: 附注:the temporary was destroyed at the end of the full expression ‘recipe_dictionary::get_uncraft(((& i)->item::typeId().string_id::operator==(itype_disassembly) ? item_components::only_item()().item::typeId() : (& i)->item::typeId()))’
1344 | const recipe &r = recipe_dictionary::get_uncraft( ( i.typeId() == itype_disassembly ) ?
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1345 | i.components.only_item().typeId() : i.typeId() );
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/activity_item_handling.cpp: In function ‘std::unordered_set<coords::coord_point<tripoint, coords::origin::abs, coords::scale::map_square> > generic_multi_activity_locations(Character&, const activity_id&)’:
src/activity_item_handling.cpp:2506:35: 错误:possibly dangling reference to a temporary [-Werror=dangling-reference]
2506 | const furn_t &f = here.furn( elem ).obj();
| ^
src/activity_item_handling.cpp:2506:60: 附注:the temporary was destroyed at the end of the full expression ‘(& here)->map::furn((* & elem)).int_id<furn_t>::obj()’
2506 | const furn_t &f = here.furn( elem ).obj();
| ~~~~~~~~~~~~~~~~~~~~~^~
src/activity_item_handling.cpp: In function ‘bool generic_multi_activity_do(Character&, const activity_id&, const activity_reason_info&, const tripoint_abs_ms&, const tripoint_bub_ms&)’:
src/activity_item_handling.cpp:2963:35: 错误:possibly dangling reference to a temporary [-Werror=dangling-reference]
2963 | const recipe &r = ( elem.typeId() == itype_disassembly ) ? elem.get_making() :
| ^
src/activity_item_handling.cpp:2964:69: 附注:the temporary was destroyed at the end of the full expression ‘recipe_dictionary::get_uncraft((& elem)->item::typeId())’
2964 | recipe_dictionary::get_uncraft( elem.typeId() );
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
在文件作用域:
cc1plus: 附注:unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
cc1plus:所有的警告都被当作是错误
make: *** [Makefile:975: obj/tiles/activity_item_handling.o] Error 1
src/activity_actor.cpp: In function ‘hack_type get_hack_type(const tripoint&)’:
src/activity_actor.cpp:749:19: 错误:possibly dangling reference to a temporary [-Werror=dangling-reference]
749 | const furn_t &xfurn_t = here.furn( examp ).obj();
| ^~~~~~~
src/activity_actor.cpp:749:51: 附注:the temporary was destroyed at the end of the full expression ‘(& here)->map::furn((* & examp)).int_id<furn_t>::obj()’
749 | const furn_t &xfurn_t = here.furn( examp ).obj();
| ~~~~~~~~~~~~~~~~~~~~~~^~
src/activity_actor.cpp:750:18: 错误:possibly dangling reference to a temporary [-Werror=dangling-reference]
750 | const ter_t &xter_t = here.ter( examp ).obj();
| ^~~~~~
src/activity_actor.cpp:750:48: 附注:the temporary was destroyed at the end of the full expression ‘(& here)->map::ter((* & examp)).int_id<ter_t>::obj()’
750 | const ter_t &xter_t = here.ter( examp ).obj();
| ~~~~~~~~~~~~~~~~~~~~~^~
在文件作用域:
cc1plus: 附注:unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
cc1plus:所有的警告都被当作是错误
make: *** [Makefile:975: obj/tiles/activity_actor.o] Error 1

Steps to reproduce

Build using GCC13.

Expected behavior

Build success.

Screenshots

No response

Versions and configuration

gcc (GCC) 13.1.1 20230426 (Red Hat 13.1.1-1) build error
clang version 16.0.1 (Fedora 16.0.1-1.fc38) works
Linux fedora 6.2.13-300.fc38.x86_64
cdda commit hash: 9f7c25d

Additional context

Probably related to:
#64210

I use my own build script:
https://github.com/tim110011/CDDA-fedora-build-script

Some question:
My machine have 8Gib memory, build cdda with clang comsume more memory and compile time than gcc, in this topic : #59424 NetSysFiresays reason is LTO.

  1. Are there some LOT and non-LOT build performance comparsion? Found nothing here: add compiler LTO support #16166
  2. I saw MOLD in Makefile option, can i use MOLD linker with GCC for lesser linking time?
@tim110011 tim110011 added the (S1 - Need confirmation) Report waiting on confirmation of reproducibility label May 3, 2023
@andrei8l
Copy link
Contributor

andrei8l commented May 3, 2023

Those looks like compiler bugs. The int_id<>s get destroyed but the objects they refer to are stored elsewhere. There are several upstream bug reports about this, for example this one.

Some of them can be worked around easily like this:

action patch
diff --git a/src/action.cpp b/src/action.cpp
index 025a6e0160..687b1751cf 100644
--- a/src/action.cpp
+++ b/src/action.cpp
@@ -670,16 +670,16 @@ bool can_examine_at( const tripoint &p, bool with_pickup )
     if( with_pickup && !here.has_flag( ter_furn_flag::TFLAG_SEALED, p ) && here.has_items( p ) ) {
         return true;
     }
-    const furn_t &xfurn_t = here.furn( p ).obj();
-    const ter_t &xter_t = here.ter( p ).obj();
+    const furn_id xfurn_t = here.furn( p );
+    const ter_id xter_t = here.ter( p );
 
-    if( here.has_furn( p ) && xfurn_t.can_examine( p ) ) {
+    if( here.has_furn( p ) && xfurn_t->can_examine( p ) ) {
         return true;
     }
     if( here.partial_con_at( tripoint_bub_ms( p ) ) != nullptr ) {
         return true;
     }
-    if( xter_t.can_examine( p ) ) {
+    if( xter_t->can_examine( p ) ) {
         return true;
     }
 

but it's probably better to disable -Wdangling-reference and let ASan catch those issues instead.

@RenechCDDA
Copy link
Member

Should be resolved by #65542

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
(S1 - Need confirmation) Report waiting on confirmation of reproducibility
Projects
None yet
Development

No branches or pull requests

3 participants