Bug 278711 - math/sprng: BROKEN with recent clang
Summary: math/sprng: BROKEN with recent clang
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-03 07:43 UTC by Thierry Thomas
Modified: 2024-05-04 13:32 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thierry Thomas freebsd_committer freebsd_triage 2024-05-03 07:43:58 UTC
With recent clang on -CURRENT, SPRNG does not compile anymore:

c++ -DHAVE_CONFIG_H -I. -I..   -isystem /usr/local/include -I../include -I. -O2 -pipe -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing  -isystem /usr/local/include  -Wno-deprecated -DLONG64=long -MT wolff_tmp-wolff.o -MD -MP -MF .deps/wolff_tmp-wolff.Tpo -c -o wolff_tmp-wolff.o `test -f 'wolff.cpp' || echo './'`wolff.cpp
wolff.cpp:76:2: error: reference to 'stack' is ambiguous
   76 |         stack[++Ipt]=nnJ;
      |         ^
wolff.cpp:17:27: note: candidate found by name lookup is 'stack'
   17 | int lattice_size, *spin, *stack, nsites;
      |                           ^
/usr/include/c++/v1/stack:156:28: note: candidate found by name lookup is 'std::stack'
  156 | class _LIBCPP_TEMPLATE_VIS stack {
      |                            ^
wolff.cpp:81:4: error: reference to 'stack' is ambiguous
   81 |         i=stack[Ipt];
      |           ^
wolff.cpp:17:27: note: candidate found by name lookup is 'stack'
   17 | int lattice_size, *spin, *stack, nsites;
      |                           ^
/usr/include/c++/v1/stack:156:28: note: candidate found by name lookup is 'std::stack'
  156 | class _LIBCPP_TEMPLATE_VIS stack {
      |                            ^
wolff.cpp:219:3: error: reference to 'stack' is ambiguous
  219 |   stack = static_cast<int *>(malloc(nsites*sizeof(int)));
      |   ^
wolff.cpp:17:27: note: candidate found by name lookup is 'stack'
   17 | int lattice_size, *spin, *stack, nsites;
      |                           ^
/usr/include/c++/v1/stack:156:28: note: candidate found by name lookup is 'std::stack'
  156 | class _LIBCPP_TEMPLATE_VIS stack {
      |                            ^
wolff.cpp:220:16: error: reference to 'stack' is ambiguous
  220 |   if(!spin || !stack)
      |                ^
wolff.cpp:17:27: note: candidate found by name lookup is 'stack'
   17 | int lattice_size, *spin, *stack, nsites;
      |                           ^
/usr/include/c++/v1/stack:156:28: note: candidate found by name lookup is 'std::stack'
  156 | class _LIBCPP_TEMPLATE_VIS stack {
      |                            ^
4 errors generated.

Full log available at https://pkg-status.freebsd.org/beefy18/data/main-amd64-default/p3d9e1b959610_sb07689d1f2a/logs/SPRNG-5.0_2.log
Comment 1 Dimitry Andric freebsd_committer freebsd_triage 2024-05-03 10:54:45 UTC
I would guess that the code in question has "using namespace std;" at the top? That is most likely the cause for this error: the local variable name 'stack' now conflicts with 'std::stack'.

It would be more correct to remove the "using namespace std;" statement and fix up the instances of std types used in the source, but an easier fix is to rename the local 'stack' variable to something else, for instance 'stack_' or 'my_stack'.
Comment 2 Thierry Thomas freebsd_committer freebsd_triage 2024-05-04 13:32:06 UTC
Committed, thanks Dimitry!
Comment 3 commit-hook freebsd_committer freebsd_triage 2024-05-04 13:32:53 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=d05586213892764617a96edec7151b464b1906ff

commit d05586213892764617a96edec7151b464b1906ff
Author:     Thierry Thomas <thierry@FreeBSD.org>
AuthorDate: 2024-05-04 13:21:44 +0000
Commit:     Thierry Thomas <thierry@FreeBSD.org>
CommitDate: 2024-05-04 13:32:02 +0000

    math/sprng: fix build with clang 18

    This is not a bug of clang. Patch suggested by dim@.

    PR:             278711

 .../files/patch-TESTS_mpitests_wolff.cpp (new)     | 37 ++++++++++++++++++++++
 math/sprng/files/patch-TESTS_wolff.cpp (new)       | 37 ++++++++++++++++++++++
 math/sprng/files/patch-TESTS_wolfftest.cpp (new)   | 37 ++++++++++++++++++++++
 3 files changed, 111 insertions(+)