Skip to content

#include <iostream> makes it impossible to use pipe as a variable name #79782

@hewillk

Description

@hewillk
Contributor
#include <iostream>

int pipe;

https://godbolt.org/z/fqPhTzq1E
The latest libc++ rejects the above code with:

<source>:3:5: error: redefinition of 'pipe' as different kind of symbol
    3 | int pipe;
      |     ^
/usr/include/unistd.h:437:12: note: previous definition is here
  437 | extern int pipe (int __pipedes[2]) __THROW __wur;
      |            ^
1 error generated.

Note that Clang-17's libc++, libc++, and MSVC-STL accept it.

Activity

added
libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
and removed on Jan 29, 2024
mordante

mordante commented on Jan 29, 2024

@mordante
Member

Mainly curious where did you spot this?
The issue is due to including unistd.h which is needed for isatty. I'm surprised it's not an issue for libstdc++, I'm sure they use isatty too (https://cplusplus.github.io/LWG/issue4044).

frederick-vs-ja

frederick-vs-ja commented on Jan 30, 2024

@frederick-vs-ja
Contributor

Mainly curious where did you spot this? The issue is due to including unistd.h which is needed for isatty. I'm surprised it's not an issue for libstdc++, I'm sure they use isatty too (https://cplusplus.github.io/LWG/issue4044).

libstdc++ only includes <unistd.h> in a separately compiled source file in order to avoid name conflict.
https://github.com/gcc-mirror/gcc/blob/f22a7ae8a96f7e5e330b12bd5045424619aa4926/libstdc%2B%2B-v3/src/c%2B%2B23/print.cc

hewillk

hewillk commented on Jan 30, 2024

@hewillk
ContributorAuthor

Mainly curious where did you spot this?

I had a small piece of code that defined a namespace named pipe, and then suddenly found that it could not be compiled in clang-trunk.

mordante

mordante commented on Feb 2, 2024

@mordante
Member

Thanks for the info. I'm testing a patch now once approved I'll request to cherry-pick it to the LLVM-18 release branch.

4 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @mordante@EugeneZelenko@frederick-vs-ja@hewillk

    Issue actions

      `#include <iostream>` makes it impossible to use `pipe` as a variable name · Issue #79782 · llvm/llvm-project