LastKismet's blog

By LastKismet, history, 2 hours ago, In English

I discovered this problem in last night's contest. My code produced a compilation error, but it runs successfully locally.

After eliminating a bunch of warnings caused by my default source, I can only get this information:

Can't compile file:
program.cpp: In lambda function:
program.cpp: In instantiation of 'LK::MAIN()::<lambda(this auto:58, LK::ll, int)> [with auto:58 = LK::MAIN()::<lambda(this auto:58, LK::ll, int)>; LK::ll = long long int]':
program.cpp:186:9:   required from here
  186 |                 if(chk(lmt,i)){
      |                    ~~~^~~~~~~
program.cpp:170:30: internal compiler error: in tsubst_expr, at cp/pt.cc:21523
  170 |                 sto pil f[1<<N-1];
      |                              ^
Please submit a full bug report, with preprocessed source (by using -freport-bug).
See <https://github.com/msys2/MINGW-packages/issues> for instructions.

After my debugging, the problem occurs in the code of the following format:

void func(){
	const int N=18;
	auto Func=[&](this auto Func,int x)->void{
		static int f[1<<N-1];
	};Func(1);
}
  • When the size of the f array is N, it has no problem; but even if changed to N-1, it still cannot run.
  • If Func is not called, there is no problem.
  • When I move the definition of N outside the func function, it doesn't have any problems.
  • Changing the definition of N to constexpr alone does not solve the problem. However, when I add static in front, both const and constexpr can run successfully.
  • When I delete the 'this auto' parameter, it can run successfully.

All of the above tests are the results returned by Codeforces after submitting the code, I hope I remember correctly. In any case, under all the situations I mentioned above, this code can run smoothly in my local environment.

My local environment is "g++(Rev8, Built by MSYS2 project) 15.2.0" in Windows11, and the Args used during compilation are "-std=c++23 -O2 -Wl,--stack=1073741824 -g".

In any case, I noticed that Codeforces is currently using GNU G++23 14.2 (64bit, msys2). I don't know much about the compilation environment, but I guess that if the '14.2' and '15.2' mentioned above do refer to the same thing, perhaps using a newer version might solve the problem?

Please forgive the stiff mechanical translation. I sincerely hope that this problem can be answered and resolved.

I am not sure how to properly and effectively give feedback on this issue, so I am posting it here. If anyone can help me provide feedback that can be seen, I would be very grateful.

  • Vote: I like it
  • +5
  • Vote: I do not like it