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

[BUG] Interpolation lowers unparenthesized #828

Closed
JohelEGP opened this issue Nov 15, 2023 · 4 comments
Closed

[BUG] Interpolation lowers unparenthesized #828

JohelEGP opened this issue Nov 15, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@JohelEGP
Copy link
Contributor

JohelEGP commented Nov 15, 2023

Title: Interpolation lowers unparenthesized.

Minimal reproducer (https://cpp2.godbolt.org/z/nzzPsq8n6):

main: () = {
  "`(0)$`".clear();
}
Commands:
cppfront main.cpp2
clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp

Expected result: CPP2_UFCS_0(clear, ("`" + cpp2::to_string(0) + "`"));

Actual result and error: "`" + cpp2::to_string(0) + CPP2_UFCS_0(clear, "`");

Cpp2 lowered to Cpp1:
#define CPP2_USE_SOURCE_LOCATION Yes

//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"



//=== Cpp2 type definitions and function declarations ===========================

auto main() -> int;
  

//=== Cpp2 function definitions =================================================

auto main() -> int{
  "`" + cpp2::to_string(0) + CPP2_UFCS_0(clear, "`");
}
Output:
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:470:44: warning: unused parameter 'where' [-Wunused-parameter]
  470 | auto assert_in_bounds(auto&& x, auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto)
      |                                            ^
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:369:76: note: expanded from macro 'CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT'
  369 |     #define CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT , std::source_location where = std::source_location::current()
      |                                                                            ^
build/main.cpp:19:42: error: use of undeclared identifier 'clear'
   19 |   "`" + cpp2::to_string(0) + CPP2_UFCS_0(clear, "`");
      |                                          ^
build/main.cpp:19:30: note: in instantiation of function template specialization 'main()::(anonymous class)::operator()<const char (&)[2]>' requested here
   19 |   "`" + cpp2::to_string(0) + CPP2_UFCS_0(clear, "`");
      |                              ^
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:797:2: note: expanded from macro 'CPP2_UFCS_0'
  797 | }(PARAM1)
      |  ^
1 warning and 1 error generated.
@JohelEGP JohelEGP added the bug Something isn't working label Nov 15, 2023
@JohelEGP
Copy link
Contributor Author

JohelEGP commented Jan 9, 2024

I have always thought that interpolation should use absl::concat.
That would fix the problem.

@hsutter hsutter closed this as completed in acab5c3 Jan 9, 2024
@hsutter
Copy link
Owner

hsutter commented Jan 9, 2024

Thanks! I might do something similar to absl::StrCat in the future, without an Abseil dependency.

@JohelEGP
Copy link
Contributor Author

JohelEGP commented Jan 9, 2024

Thank you!
I first rediscovered this issue
when I used one of those functions to color strings (from #831 (comment))
and noticed that only a latter part of the string was colored.

@JohelEGP
Copy link
Contributor Author

JohelEGP commented Sep 22, 2024

Commit 13826c5 regressed
commit acab5c3 (which didn't add a test).
Although according to commit 3a8874a,

Note that "interpolate('d')$ string".ufcs_call() now requires parens, ("interpolate('d')$ string").ufcs_call()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants