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

Don't use a refrence into an rvalue object #11965

Merged
merged 3 commits into from
Sep 12, 2023
Merged

Conversation

daschuer
Copy link
Member

This should fix the empty filename in the taglib error message
#11964

Maybe one can share some C++ knowledge, was

const std::wstring& filename = file.name().wstr();

not allowed or is it a compiler bug?

with const std::wstring &wstr() const;
and file name() returns by value.

@Swiftb0y
Copy link
Member

not allowed or is it a compiler bug?

I would've guessed that it was valid due to lifetime extension, but gcc and clang disagree.
https://compiler-explorer.com/z/sfhfz3scc

Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

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

please fix the compile errors and amend.

Comment on lines 120 to 124
// For _WIN32 there are two types std::string and std::wstring
// we must pick one explicit,
// to prevent "use of overloaded operator '<<' is ambiguous" error
// on clang-cl builds.
TagLib::FileName filename = file.name();
Copy link
Member

Choose a reason for hiding this comment

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

I think the best way to fix this would be something like this:

#ifdef _WIN32
TagLib::FileName filename_owning = file.name();
auto filename = std::basic_string_view(filename_owning.wstr());
#else 
auto filename = std::basic_string_view(file.name());
#endif

this is polymorphic over the CharT thanks to CTAD and does not involve conversion. Could be even simpler if we use just convert to char* on windows directly, or was there a reason to use the wide variant?

Copy link
Member

Choose a reason for hiding this comment

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

I wonder what implications the unfortunate API design has for ownership? Eg is file.name() just leaking the string if not on windows?

Copy link
Member Author

Choose a reason for hiding this comment

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

file.name() is just a non owning pointer to the original string on Linux/MacOS
I have kept the native types for filename to have this issue more visible.

Copy link
Member

Choose a reason for hiding this comment

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

okay, so no leaks, just extra memory allocation on windows it seems.

Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

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

LGTM. waiting for CI

daschuer and others added 2 commits September 12, 2023 00:17
This should fix the empty filename in the taglib error message
Co-authored-by: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com>
@Swiftb0y
Copy link
Member

I should start caring about the whitespace in my suggestions. These pre-commit trailing whitespace failures are annoying. I'm sorry. Can you please fix and amend? Thank you.

Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

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

LGTM thank you.

@Swiftb0y Swiftb0y merged commit b6e29b4 into mixxxdj:2.4 Sep 12, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants