Commit d5e9e0c3 by Gennadiy Civil

Merge pull request #2397 from kuzkry:custom-type-traits-is_reference

PiperOrigin-RevId: 264193098
parents 30e58a89 da76d01b
...@@ -532,7 +532,7 @@ class ReturnAction { ...@@ -532,7 +532,7 @@ class ReturnAction {
// in the Impl class. But both definitions must be the same. // in the Impl class. But both definitions must be the same.
typedef typename Function<F>::Result Result; typedef typename Function<F>::Result Result;
GTEST_COMPILE_ASSERT_( GTEST_COMPILE_ASSERT_(
!is_reference<Result>::value, !std::is_reference<Result>::value,
use_ReturnRef_instead_of_Return_to_return_a_reference); use_ReturnRef_instead_of_Return_to_return_a_reference);
static_assert(!std::is_void<Result>::value, static_assert(!std::is_void<Result>::value,
"Can't use Return() on an action expected to return `void`."); "Can't use Return() on an action expected to return `void`.");
...@@ -561,7 +561,7 @@ class ReturnAction { ...@@ -561,7 +561,7 @@ class ReturnAction {
Result Perform(const ArgumentTuple&) override { return value_; } Result Perform(const ArgumentTuple&) override { return value_; }
private: private:
GTEST_COMPILE_ASSERT_(!is_reference<Result>::value, GTEST_COMPILE_ASSERT_(!std::is_reference<Result>::value,
Result_cannot_be_a_reference_type); Result_cannot_be_a_reference_type);
// We save the value before casting just in case it is being cast to a // We save the value before casting just in case it is being cast to a
// wrapper type. // wrapper type.
...@@ -640,7 +640,7 @@ class ReturnRefAction { ...@@ -640,7 +640,7 @@ class ReturnRefAction {
// Asserts that the function return type is a reference. This // Asserts that the function return type is a reference. This
// catches the user error of using ReturnRef(x) when Return(x) // catches the user error of using ReturnRef(x) when Return(x)
// should be used, and generates some helpful error message. // should be used, and generates some helpful error message.
GTEST_COMPILE_ASSERT_(internal::is_reference<Result>::value, GTEST_COMPILE_ASSERT_(std::is_reference<Result>::value,
use_Return_instead_of_ReturnRef_to_return_a_value); use_Return_instead_of_ReturnRef_to_return_a_value);
return Action<F>(new Impl<F>(ref_)); return Action<F>(new Impl<F>(ref_));
} }
...@@ -687,7 +687,7 @@ class ReturnRefOfCopyAction { ...@@ -687,7 +687,7 @@ class ReturnRefOfCopyAction {
// catches the user error of using ReturnRefOfCopy(x) when Return(x) // catches the user error of using ReturnRefOfCopy(x) when Return(x)
// should be used, and generates some helpful error message. // should be used, and generates some helpful error message.
GTEST_COMPILE_ASSERT_( GTEST_COMPILE_ASSERT_(
internal::is_reference<Result>::value, std::is_reference<Result>::value,
use_Return_instead_of_ReturnRefOfCopy_to_return_a_value); use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
return Action<F>(new Impl<F>(value_)); return Action<F>(new Impl<F>(value_));
} }
......
...@@ -280,7 +280,7 @@ class SafeMatcherCastImpl { ...@@ -280,7 +280,7 @@ class SafeMatcherCastImpl {
// Enforce that we are not converting a non-reference type T to a reference // Enforce that we are not converting a non-reference type T to a reference
// type U. // type U.
GTEST_COMPILE_ASSERT_( GTEST_COMPILE_ASSERT_(
internal::is_reference<T>::value || !internal::is_reference<U>::value, std::is_reference<T>::value || !std::is_reference<U>::value,
cannot_convert_non_reference_arg_to_reference); cannot_convert_non_reference_arg_to_reference);
// In case both T and U are arithmetic types, enforce that the // In case both T and U are arithmetic types, enforce that the
// conversion is not lossy. // conversion is not lossy.
......
...@@ -105,7 +105,7 @@ ACTION_TEMPLATE(SetArgReferee, ...@@ -105,7 +105,7 @@ ACTION_TEMPLATE(SetArgReferee,
// Ensures that argument #k is a reference. If you get a compiler // Ensures that argument #k is a reference. If you get a compiler
// error on the next line, you are using SetArgReferee<k>(value) in // error on the next line, you are using SetArgReferee<k>(value) in
// a mock function whose k-th (0-based) argument is not a reference. // a mock function whose k-th (0-based) argument is not a reference.
GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value, GTEST_COMPILE_ASSERT_(std::is_reference<argk_type>::value,
SetArgReferee_must_be_used_with_a_reference_argument); SetArgReferee_must_be_used_with_a_reference_argument);
::std::get<k>(args) = value; ::std::get<k>(args) = value;
} }
......
...@@ -336,10 +336,6 @@ GTEST_API_ WithoutMatchers GetWithoutMatchers(); ...@@ -336,10 +336,6 @@ GTEST_API_ WithoutMatchers GetWithoutMatchers();
// Type traits. // Type traits.
// is_reference<T>::value is non-zero if T is a reference type.
template <typename T> struct is_reference : public false_type {};
template <typename T> struct is_reference<T&> : public true_type {};
// remove_reference<T>::type removes the reference from type T, if any. // remove_reference<T>::type removes the reference from type T, if any.
template <typename T> struct remove_reference { typedef T type; }; // NOLINT template <typename T> struct remove_reference { typedef T type; }; // NOLINT
template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT
......
...@@ -513,12 +513,6 @@ TEST(TypeTraitsTest, false_type) { ...@@ -513,12 +513,6 @@ TEST(TypeTraitsTest, false_type) {
EXPECT_FALSE(false_type::value); EXPECT_FALSE(false_type::value);
} }
TEST(TypeTraitsTest, is_reference) {
EXPECT_FALSE(is_reference<int>::value);
EXPECT_FALSE(is_reference<char*>::value);
EXPECT_TRUE(is_reference<const int&>::value);
}
TEST(TypeTraitsTest, remove_reference) { TEST(TypeTraitsTest, remove_reference) {
EXPECT_TRUE((std::is_same<char, remove_reference<char&>::type>::value)); EXPECT_TRUE((std::is_same<char, remove_reference<char&>::type>::value));
EXPECT_TRUE( EXPECT_TRUE(
......
...@@ -172,7 +172,6 @@ def FuseGTestH(gtest_root, output_dir): ...@@ -172,7 +172,6 @@ def FuseGTestH(gtest_root, output_dir):
output_file.write(line) output_file.write(line)
ProcessFile(GTEST_H_SEED) ProcessFile(GTEST_H_SEED)
ProcessFile(GTEST_SPI_H_SEED)
output_file.close() output_file.close()
...@@ -194,15 +193,20 @@ def FuseGTestAllCcToFile(gtest_root, output_file): ...@@ -194,15 +193,20 @@ def FuseGTestAllCcToFile(gtest_root, output_file):
for line in open(os.path.join(gtest_root, gtest_source_file), 'r'): for line in open(os.path.join(gtest_root, gtest_source_file), 'r'):
m = INCLUDE_GTEST_FILE_REGEX.match(line) m = INCLUDE_GTEST_FILE_REGEX.match(line)
if m: if m:
# It's '#include "gtest/foo.h"'. if 'include/' + m.group(1) == GTEST_SPI_H_SEED:
# We treat it as '#include "gtest/gtest.h"', as all other # It's '#include "gtest/gtest-spi.h"'. This file is not
# gtest headers are being fused into gtest.h and cannot be # #included by "gtest/gtest.h", so we need to process it.
# #included directly. ProcessFile(GTEST_SPI_H_SEED)
else:
# There is no need to #include "gtest/gtest.h" more than once. # It's '#include "gtest/foo.h"' where foo is not gtest-spi.
if not GTEST_H_SEED in processed_files: # We treat it as '#include "gtest/gtest.h"', as all other
processed_files.add(GTEST_H_SEED) # gtest headers are being fused into gtest.h and cannot be
output_file.write('#include "%s"\n' % (GTEST_H_OUTPUT,)) # #included directly.
# There is no need to #include "gtest/gtest.h" more than once.
if not GTEST_H_SEED in processed_files:
processed_files.add(GTEST_H_SEED)
output_file.write('#include "%s"\n' % (GTEST_H_OUTPUT,))
else: else:
m = INCLUDE_SRC_FILE_REGEX.match(line) m = INCLUDE_SRC_FILE_REGEX.match(line)
if m: if m:
......
#!/usr/bin/env python
#
# Copyright 2013 Google Inc. All Rights Reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Script for branching Google Test/Mock wiki pages for a new version.
SYNOPSIS
release_docs.py NEW_RELEASE_VERSION
Google Test and Google Mock's external user documentation is in
interlinked wiki files. When we release a new version of
Google Test or Google Mock, we need to branch the wiki files
such that users of a specific version of Google Test/Mock can
look up documenation relevant for that version. This script
automates that process by:
- branching the current wiki pages (which document the
behavior of the SVN trunk head) to pages for the specified
version (e.g. branching FAQ.wiki to V2_6_FAQ.wiki when
NEW_RELEASE_VERSION is 2.6);
- updating the links in the branched files to point to the branched
version (e.g. a link in V2_6_FAQ.wiki that pointed to
Primer.wiki#Anchor will now point to V2_6_Primer.wiki#Anchor).
NOTE: NEW_RELEASE_VERSION must be a NEW version number for
which the wiki pages don't yet exist; otherwise you'll get SVN
errors like "svn: Path 'V1_7_PumpManual.wiki' is not a
directory" when running the script.
EXAMPLE
$ cd PATH/TO/GTEST_SVN_WORKSPACE/trunk
$ scripts/release_docs.py 2.6 # create wiki pages for v2.6
$ svn status # verify the file list
$ svn diff # verify the file contents
$ svn commit -m "release wiki pages for v2.6"
"""
__author__ = 'wan@google.com (Zhanyong Wan)'
import os
import re
import sys
import common
# Wiki pages that shouldn't be branched for every gtest/gmock release.
GTEST_UNVERSIONED_WIKIS = ['DevGuide.wiki']
GMOCK_UNVERSIONED_WIKIS = [
'DesignDoc.wiki',
'DevGuide.wiki',
'KnownIssues.wiki'
]
def DropWikiSuffix(wiki_filename):
"""Removes the .wiki suffix (if any) from the given filename."""
return (wiki_filename[:-len('.wiki')] if wiki_filename.endswith('.wiki')
else wiki_filename)
class WikiBrancher(object):
"""Branches ..."""
def __init__(self, dot_version):
self.project, svn_root_path = common.GetSvnInfo()
if self.project not in ('googletest', 'googlemock'):
sys.exit('This script must be run in a gtest or gmock SVN workspace.')
self.wiki_dir = svn_root_path + '/wiki'
# Turn '2.6' to 'V2_6_'.
self.version_prefix = 'V' + dot_version.replace('.', '_') + '_'
self.files_to_branch = self.GetFilesToBranch()
page_names = [DropWikiSuffix(f) for f in self.files_to_branch]
# A link to Foo.wiki is in one of the following forms:
# [Foo words]
# [Foo#Anchor words]
# [http://code.google.com/.../wiki/Foo words]
# [http://code.google.com/.../wiki/Foo#Anchor words]
# We want to replace 'Foo' with 'V2_6_Foo' in the above cases.
self.search_for_re = re.compile(
# This regex matches either
# [Foo
# or
# /wiki/Foo
# followed by a space or a #, where Foo is the name of an
# unversioned wiki page.
r'(\[|/wiki/)(%s)([ #])' % '|'.join(page_names))
self.replace_with = r'\1%s\2\3' % (self.version_prefix,)
def GetFilesToBranch(self):
"""Returns a list of .wiki file names that need to be branched."""
unversioned_wikis = (GTEST_UNVERSIONED_WIKIS if self.project == 'googletest'
else GMOCK_UNVERSIONED_WIKIS)
return [f for f in os.listdir(self.wiki_dir)
if (f.endswith('.wiki') and
not re.match(r'^V\d', f) and # Excluded versioned .wiki files.
f not in unversioned_wikis)]
def BranchFiles(self):
"""Branches the .wiki files needed to be branched."""
print 'Branching %d .wiki files:' % (len(self.files_to_branch),)
os.chdir(self.wiki_dir)
for f in self.files_to_branch:
command = 'svn cp %s %s%s' % (f, self.version_prefix, f)
print command
os.system(command)
def UpdateLinksInBranchedFiles(self):
for f in self.files_to_branch:
source_file = os.path.join(self.wiki_dir, f)
versioned_file = os.path.join(self.wiki_dir, self.version_prefix + f)
print 'Updating links in %s.' % (versioned_file,)
text = file(source_file, 'r').read()
new_text = self.search_for_re.sub(self.replace_with, text)
file(versioned_file, 'w').write(new_text)
def main():
if len(sys.argv) != 2:
sys.exit(__doc__)
brancher = WikiBrancher(sys.argv[1])
brancher.BranchFiles()
brancher.UpdateLinksInBranchedFiles()
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment