Skip to content

Commit 679f8a8

Browse files
committed
[libc++] Move fpos into its own header
For some reason `<string>` defines `std::fpos`, which should be defined in `<ios>`. Reviewed By: Quuxplusone, Mordante, #libc Spies: libcxx-commits, mgorny Differential Revision: https://reviews.llvm.org/D118914
1 parent 6987363 commit 679f8a8

File tree

7 files changed

+109
-45
lines changed

7 files changed

+109
-45
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ set(files
218218
__functional/weak_result_type.h
219219
__functional_base
220220
__hash_table
221+
__ios/fpos.h
221222
__iterator/access.h
222223
__iterator/advance.h
223224
__iterator/back_insert_iterator.h

libcxx/include/__ios/fpos.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP___IOS_FPOS_H
11+
#define _LIBCPP___IOS_FPOS_H
12+
13+
#include <__config>
14+
#include <iosfwd>
15+
16+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17+
# pragma GCC system_header
18+
#endif
19+
20+
_LIBCPP_BEGIN_NAMESPACE_STD
21+
22+
template <class _StateT>
23+
class _LIBCPP_TEMPLATE_VIS fpos {
24+
private:
25+
_StateT __st_;
26+
streamoff __off_;
27+
28+
public:
29+
_LIBCPP_HIDE_FROM_ABI fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
30+
31+
_LIBCPP_HIDE_FROM_ABI operator streamoff() const { return __off_; }
32+
33+
_LIBCPP_HIDE_FROM_ABI _StateT state() const { return __st_; }
34+
_LIBCPP_HIDE_FROM_ABI void state(_StateT __st) { __st_ = __st; }
35+
36+
_LIBCPP_HIDE_FROM_ABI fpos& operator+=(streamoff __off) {
37+
__off_ += __off;
38+
return *this;
39+
}
40+
41+
_LIBCPP_HIDE_FROM_ABI fpos operator+(streamoff __off) const {
42+
fpos __t(*this);
43+
__t += __off;
44+
return __t;
45+
}
46+
47+
_LIBCPP_HIDE_FROM_ABI fpos& operator-=(streamoff __off) {
48+
__off_ -= __off;
49+
return *this;
50+
}
51+
52+
_LIBCPP_HIDE_FROM_ABI fpos operator-(streamoff __off) const {
53+
fpos __t(*this);
54+
__t -= __off;
55+
return __t;
56+
}
57+
};
58+
59+
template <class _StateT>
60+
inline _LIBCPP_HIDE_FROM_ABI
61+
streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y) {
62+
return streamoff(__x) - streamoff(__y);
63+
}
64+
65+
template <class _StateT>
66+
inline _LIBCPP_HIDE_FROM_ABI
67+
bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y) {
68+
return streamoff(__x) == streamoff(__y);
69+
}
70+
71+
template <class _StateT>
72+
inline _LIBCPP_HIDE_FROM_ABI
73+
bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y) {
74+
return streamoff(__x) != streamoff(__y);
75+
}
76+
77+
_LIBCPP_END_NAMESPACE_STD
78+
79+
#endif // _LIBCPP___IOS_FPOS_H

libcxx/include/ios

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ storage-class-specifier const error_category& iostream_category() noexcept;
211211
*/
212212

213213
#include <__config>
214+
#include <__ios/fpos.h>
214215
#include <__locale>
215216
#include <iosfwd>
216217
#include <system_error>

libcxx/include/module.modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,10 @@ module std [system] {
575575
header "ios"
576576
export iosfwd
577577
export *
578+
579+
module __ios {
580+
module fpos { private header "__ios/fpos.h" }
581+
}
578582
}
579583
module iosfwd {
580584
header "iosfwd"

libcxx/include/string

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++1
521521
#include <__config>
522522
#include <__debug>
523523
#include <__functional_base>
524+
#include <__ios/fpos.h>
524525
#include <__iterator/wrap_iter.h>
525526
#include <algorithm>
526527
#include <compare>
@@ -538,11 +539,11 @@ basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++1
538539
#include <version>
539540

540541
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
541-
# include <cwchar>
542+
# include <cwchar>
542543
#endif
543544

544545
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
545-
# include <cstdint>
546+
# include <cstdint>
546547
#endif
547548

548549
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -555,43 +556,6 @@ _LIBCPP_PUSH_MACROS
555556

556557
_LIBCPP_BEGIN_NAMESPACE_STD
557558

558-
// fpos
559-
560-
template <class _StateT>
561-
class _LIBCPP_TEMPLATE_VIS fpos
562-
{
563-
private:
564-
_StateT __st_;
565-
streamoff __off_;
566-
public:
567-
_LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
568-
569-
_LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
570-
571-
_LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
572-
_LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
573-
574-
_LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
575-
_LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
576-
_LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
577-
_LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
578-
};
579-
580-
template <class _StateT>
581-
inline _LIBCPP_INLINE_VISIBILITY
582-
streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
583-
{return streamoff(__x) - streamoff(__y);}
584-
585-
template <class _StateT>
586-
inline _LIBCPP_INLINE_VISIBILITY
587-
bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
588-
{return streamoff(__x) == streamoff(__y);}
589-
590-
template <class _StateT>
591-
inline _LIBCPP_INLINE_VISIBILITY
592-
bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
593-
{return streamoff(__x) != streamoff(__y);}
594-
595559
// basic_string
596560

597561
template<class _CharT, class _Traits, class _Allocator>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: modules-build
10+
11+
// WARNING: This test was generated by 'generate_private_header_tests.py'
12+
// and should not be edited manually.
13+
14+
// expected-error@*:* {{use of private header from outside its module: '__ios/fpos.h'}}
15+
#include <__ios/fpos.h>

libcxx/test/std/input.output/iostreams.base/fpos/fpos.operations/fpos.pass.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "test_macros.h"
9+
// <ios>
10+
11+
// template <class stateT>
12+
// class fpos;
1013

11-
#include <string>
1214
#include <cassert>
15+
#include <ios>
1316
#include <type_traits>
1417

15-
// <string>
16-
17-
// template <class stateT>
18-
// class fpos;
18+
#include "test_macros.h"
1919

2020
template<class T, class = void>
2121
struct is_equality_comparable : std::false_type { };

0 commit comments

Comments
 (0)