Opened 2 years ago

Closed 2 years ago

#63980 closed defect (fixed)

qca-qt5 @2.3.4: error: no member named 'rand' in namespace 'std'

Reported by: ryandesign (Ryan Carsten Schmidt) Owned by: RJVB (René Bertin)
Priority: Normal Milestone:
Component: ports Version: 2.7.1
Keywords: Cc: chrstphrchvz (Christopher Chavez), mascguy (Christopher Nielsen)
Port: qca

Description

https://build.macports.org/builders/ports-10.9_x86_64-builder/builds/166801/steps/install-port/logs/stdio

error: no member named 'rand' in namespace 'std'; did you mean simply 'rand'?
            buf[n] = (char)std::rand();
                           ^~~~~~~~~
                           rand
/usr/include/stdlib.h:159:6: note: 'rand' declared here
int      rand(void);
         ^

Change History (8)

comment:1 Changed 2 years ago by chrstphrchvz (Christopher Chavez)

Missing #include <cstdlib> for std::rand() and std::srand() (something compilers are not always strict about)? https://github.com/macports/macports-ports/pull/13010

Last edited 2 years ago by chrstphrchvz (Christopher Chavez) (previous) (diff)

comment:2 Changed 2 years ago by chrstphrchvz (Christopher Chavez)

Cc: chrstphrchvz added

comment:3 Changed 2 years ago by RJVB (René Bertin)

Thanks. Yes, I guess that my compilers didn't trip over this, but one of them tripped in a similar way over std::unique_ptr (hence the corresponding patchfile).

comment:4 Changed 2 years ago by jmroot (Joshua Root)

By the standard, including a C compatibility header (like stdlib.h) will declare the appropriate names in the global namespace, and may declare the same names in the std namespace. Fun, huh?

comment:5 Changed 2 years ago by mascguy (Christopher Nielsen)

Cc: mascguy added

comment:6 Changed 2 years ago by RJVB (René Bertin)

Fun indeed... I just observe that the documentation provided via cpppreferences suggests including the specific header for these symbols.

comment:7 in reply to:  4 Changed 2 years ago by chrstphrchvz (Christopher Chavez)

Replying to jmroot:

By the standard, including a C compatibility header (like stdlib.h) will declare the appropriate names in the global namespace, and may declare the same names in the std namespace. Fun, huh?

I didn’t notice stdlib.h being included, though I guess clang wouldn’t suggest using C functions rand()/srand() if stdlib.h weren’t included.

comment:8 Changed 2 years ago by chrstphrchvz (Christopher Chavez)

Resolution: fixed
Status: assignedclosed

In 3ce4a9cf708b73cda5833949d65241526bb77185/macports-ports (master):

qca-qt5: fix build on macOS 10.9-10.11
Fixes: #63980

Note: See TracTickets for help on using tickets.