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

Incorrect definition of wcsstr for older glibc depending on include order #62638

Closed
rupprecht opened this issue May 10, 2023 · 1 comment
Closed
Assignees
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@rupprecht
Copy link
Collaborator

This snippet fails to compile, as expected:

#include <cwchar>
#include <iosfwd>
void func() {
  wchar_t* v1;
  const wchar_t* cv2 = L"/";
  v1 = wcsstr(cv2, L"/"); // expected-error {{assigning to 'wchar_t *' from 'const wchar_t *' discards qualifiers}}
}

D148542 adds another path to including the system wchar.h without defining __CORRECT_ISO_CPP_WCHAR_H_PROTO as we do elsewhere, and older versions of glibc did not declare __CORRECT_ISO_CPP_WCHAR_H_PROTO for itself correctly when clang is the host compiler. In that situation, changing the include order causes it to unexpectedly compile:

#include <iosfwd>  // This and the next line are the only differences
#include <cwchar>
void func() {
  wchar_t* v1;
  const wchar_t* cv2 = L"/";
  v1 = wcsstr(cv2, L"/"); // Unexpectedly no error here
}

D150015 fixes this.

@rupprecht rupprecht added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label May 10, 2023
@rupprecht rupprecht self-assigned this May 10, 2023
@philnik777
Copy link
Contributor

Fixed by 0ec57bf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

2 participants