Skip to content

Commit

Permalink
Use a full string and it works...
Browse files Browse the repository at this point in the history
  • Loading branch information
Myoldmopar committed Apr 5, 2024
1 parent afe82ff commit 58bbe38
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/EnergyPlus/OutputProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2432,7 +2432,7 @@ namespace OutputProcessor {
? unitNameCustomEMS
: ((units == Constant::Units::Invalid) ? "" : Constant::unitNames[(int)units]);

std::string_view schedString = (SchedPtr != 0) ? state.dataScheduleMgr->Schedule(SchedPtr).Name : "";
std::string schedString = (SchedPtr != 0) ? state.dataScheduleMgr->Schedule(SchedPtr).Name : "";

if (state.files.eso.good()) {
print(state.files.eso,
Expand Down

7 comments on commit 58bbe38

@amirroth
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, this was the problem. Basically, state.dataScheduleMgr->Schedule(SchedPtr).Name is a std::string and "" is a const char *. In order for this to be a well formed statement, "" has to be constructed into std::string also, but that std::string is temporary (it has the lifetime of the RHS expression) and so schedString is left dangling and will point to whatever ends up in that piece of memory at the time. Apparently, this is type unification rule of the conditional operator (and always has been), I've just never run into an actual case before. TIL.

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OutputProcessor2 (Myoldmopar) - Win64-Windows-10-VisualStudio-16: OK (2766 of 2766 tests passed, 0 test warnings)

Build Badge Test Badge

@rraustad
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why not create one to use in places that create a string_view?

DataGlobalConstants:

std::string constexp blankString = "";

@amirroth
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why not create one to use in places that create a string_view?

DataGlobalConstants:

std::string constexp blankString = "";

A string cannot be a constexpr, but a const one would work. We could do that.

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OutputProcessor2 (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4: OK (3595 of 3595 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OutputProcessor2 (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-UnitTestsCoverage-Debug: OK (1978 of 1978 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OutputProcessor2 (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-IntegrationCoverage-Debug: OK (791 of 791 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

Please sign in to comment.