This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Patch] Small refactor on <regex> _State<>
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: Tim Shen <timshen at google dot com>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 30 Jul 2015 11:11:53 +0100
- Subject: Re: [Patch] Small refactor on <regex> _State<>
- Authentication-results: sourceware.org; auth=none
- References: <CAG4ZjNnYLoCYnjNpkJYHa2Q-ux0KnKmVXBDUOa33xk29MzeTKA at mail dot gmail dot com> <20150725153121 dot GW21787 at redhat dot com> <CAG4ZjNnvm=QAwihOUvMLtOezYprtasaJOY3i-MhJV0Tf4z5mpg at mail dot gmail dot com> <20150728151925 dot GO10878 at redhat dot com> <20150729083214 dot GB13355 at redhat dot com> <CAG4ZjNm0YkxLZjajuV7HaQgEGhapFybEem1wi07UMLy3Xg9+BA at mail dot gmail dot com> <20150729091543 dot GE13355 at redhat dot com> <CAG4ZjNn=Eqsmhe4QihGvpGEyadV+k4LAGdVrSJQRwKk_ve2zRg at mail dot gmail dot com> <CAG4ZjN=7nOtAibqX0KQ_XKcS7jDC-8_K0wRb5DG0Em+NtQ5xgg at mail dot gmail dot com>
On 29/07/15 21:55 -0700, Tim Shen wrote:
- typedef _Matcher<typename _TraitsT::char_type> _MatcherT;
+ typedef _Matcher<_Char_type> _MatcherT;
+ static_assert(sizeof(_MatcherT) == sizeof(_Matcher<char>),
+ "The aussmption std::function<bool(char)> has "
+ "the same size as std::function<bool(T)> is violated");
+ static_assert(alignof(_MatcherT) == alignof(_Matcher<char>),
+ "The aussmption std::function<bool(char)> has "
+ "the same alignment as std::function<bool(T)> is violated");
Good idea adding these assertions, but "aussmption" :-)
In accordance with https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41759
we should avoid negative wording ("X is not Y" or "X does not meet Y")
in static assertions, so maybe something like:
static_assert(alignof(_MatcherT) == alignof(_Matcher<char>),
"std::function<bool(T)> has the same size as "
"std::function<bool(char)>");
or:
static_assert(alignof(_MatcherT) == alignof(_Matcher<char>),
"std::function<bool(T)> must have the same size as "
"std::function<bool(char)>");
- _MatcherT _M_matches; // for _S_opcode_match
+ _MatcherT&
+ _M_get_matcher()
+ { return *reinterpret_cast<_MatcherT*>(this->_M_matcher_storage._M_addr()); }
- explicit _State(_Opcode __opcode) : _State_base(__opcode) { }
+ const _MatcherT&
+ _M_get_matcher() const
+ { return *reinterpret_cast<const _MatcherT*>(this->_M_matcher_storage._M_addr()); }
These can use static_cast, because _M_addr() returns void*
OK for trunk with those two tweaks, thanks!