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

[type-traits] add 'IsPointer<Type>' and use it in message/dataset #5735

Merged
merged 1 commit into from Oct 29, 2020

Conversation

abtink
Copy link
Member

@abtink abtink commented Oct 28, 2020

This commit adds a new header common/type_traits.hpp which provides
IsPointer<Type> to check whether a template Type is a pointer type
or not. This is then used in Message and Dataset methods where we
append/set a generic object to check (as an static_assert) that the
object type is not a pointer. This adds protection (causing a compile
time error) against potential incorrect use of these methods (i.e.,
passing a pointer instead of a reference to an object by mistake).

@size-report
Copy link

size-report bot commented Oct 28, 2020

Size Report of OpenThread

Merging #5735 into master(704f183).

name branch text data bss total
ot-cli-ftd_1.1 master 383628 736 72844 457208
#5735 383628 736 72844 457208
+/- 0 0 0 0
ot-cli-mtd_1.1 master 311052 736 64260 376048
#5735 311052 736 64260 376048
+/- 0 0 0 0
ot-ncp-ftd_1.1 master 377564 736 72124 450424
#5735 377564 736 72124 450424
+/- 0 0 0 0
ot-ncp-mtd_1.1 master 307980 736 63540 372256
#5735 307980 736 63540 372256
+/- 0 0 0 0
ot-rcp_1.1 master 64280 636 7656 72572
#5735 64280 636 7656 72572
+/- 0 0 0 0
libopenthread-cli-ftd.a_1.1 master 38284 0 3108 41392
#5735 38284 0 3108 41392
+/- 0 0 0 0
libopenthread-cli-mtd.a_1.1 master 31103 0 3108 34211
#5735 31103 0 3108 34211
+/- 0 0 0 0
libopenthread-ftd.a_1.1 master 189449 4 54992 244445
#5735 189449 4 54992 244445
+/- 0 0 0 0
libopenthread-mtd.a_1.1 master 129433 4 46408 175845
#5735 129433 4 46408 175845
+/- 0 0 0 0
libopenthread-ncp-ftd.a_1.1 master 48149 0 2388 50537
#5735 48149 0 2388 50537
+/- 0 0 0 0
libopenthread-ncp-mtd.a_1.1 master 43345 0 2388 45733
#5735 43345 0 2388 45733
+/- 0 0 0 0
libopenthread-rcp.a_1.1 master 27200 0 1532 28732
#5735 27200 0 1532 28732
+/- 0 0 0 0
libopenthread-radio.a_1.1 master 13406 0 150 13556
#5735 13406 0 150 13556
+/- 0 0 0 0
ot-cli-ftd_1.2 master 407732 736 82392 490860
#5735 407732 736 82392 490860
+/- 0 0 0 0
ot-cli-mtd_1.2 master 323364 736 64544 388644
#5735 323364 736 64544 388644
+/- 0 0 0 0
ot-ncp-ftd_1.2 master 398740 736 81672 481148
#5735 398740 736 81672 481148
+/- 0 0 0 0
ot-ncp-mtd_1.2 master 318244 736 63824 382804
#5735 318244 736 63824 382804
+/- 0 0 0 0
ot-rcp_1.2 master 70956 636 16528 88120
#5735 70956 636 16528 88120
+/- 0 0 0 0
libopenthread-cli-ftd.a_1.2 master 39933 0 3108 43041
#5735 39933 0 3108 43041
+/- 0 0 0 0
libopenthread-cli-mtd.a_1.2 master 31876 0 3108 34984
#5735 31876 0 3108 34984
+/- 0 0 0 0
libopenthread-ftd.a_1.2 master 210479 4 64440 274923
#5735 210479 4 64440 274923
+/- 0 0 0 0
libopenthread-mtd.a_1.2 master 138900 4 46592 185496
#5735 138900 4 46592 185496
+/- 0 0 0 0
libopenthread-ncp-ftd.a_1.2 master 48149 0 2388 50537
#5735 48149 0 2388 50537
+/- 0 0 0 0
libopenthread-ncp-mtd.a_1.2 master 43345 0 2388 45733
#5735 43345 0 2388 45733
+/- 0 0 0 0
libopenthread-rcp.a_1.2 master 27200 0 1532 28732
#5735 27200 0 1532 28732
+/- 0 0 0 0
libopenthread-radio.a_1.2 master 14828 0 174 15002
#5735 14828 0 174 15002
+/- 0 0 0 0

@codecov
Copy link

codecov bot commented Oct 28, 2020

Codecov Report

Merging #5735 into master will decrease coverage by 0.02%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #5735      +/-   ##
==========================================
- Coverage   82.76%   82.74%   -0.03%     
==========================================
  Files         377      377              
  Lines       48396    48396              
==========================================
- Hits        40057    40045      -12     
- Misses       8339     8351      +12     
Impacted Files Coverage Δ
src/core/common/message.hpp 100.00% <ø> (ø)
src/core/meshcop/dataset.hpp 100.00% <ø> (ø)
src/core/utils/channel_manager.cpp 82.22% <0.00%> (-4.45%) ⬇️
src/core/thread/mesh_forwarder.cpp 89.03% <0.00%> (-1.78%) ⬇️
src/core/mac/data_poll_sender.cpp 92.78% <0.00%> (-1.45%) ⬇️
src/core/thread/router_table.cpp 90.82% <0.00%> (-0.92%) ⬇️
src/core/meshcop/joiner_router.cpp 91.48% <0.00%> (-0.54%) ⬇️
src/core/meshcop/meshcop_tlvs.hpp 85.22% <0.00%> (-0.50%) ⬇️
src/lib/spinel/radio_spinel_impl.hpp 88.06% <0.00%> (-0.27%) ⬇️
src/core/thread/mle_router.cpp 90.53% <0.00%> (-0.16%) ⬇️
... and 11 more

Copy link
Contributor

@Irving-cl Irving-cl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

src/core/common/type_traits.hpp Outdated Show resolved Hide resolved
This commit adds a new header `common/type_traits.hpp` which provides
`IsPointer<Type>` to check whether a template `Type` is a pointer type
or not. This is then used in `Message` and `Dataset` methods where we
append/set a generic object to check (as an `static_assert`) that the
object type is not a pointer. This adds protection (causing a compile
time error) against potential incorrect use of these methods (i.e.,
passing a pointer instead of a reference to an object by mistake).
@jwhui jwhui merged commit ac33c75 into openthread:master Oct 29, 2020
simonlingoogle pushed a commit to simonlingoogle/openthread that referenced this pull request Nov 12, 2020
Bug: 171933690

* origin/github/master:
  [low-power] implement forward tracking series (openthread#5608)
  [efr32] radio: increase FIFO size to allow handling of heavy traffic (openthread#5742)
  [test] verify realm-local multicast on POSIX (openthread#5738)
  [clang-tidy] google-explicit-constructor (openthread#5734)
  [clang-tidy] misc-unused-using-decls (openthread#5732)
  [continuous-integration] use lcov to generate coverage data (openthread#5635)
  [type-traits] add 'IsPointer<Type>' and use it in message/dataset (openthread#5735)
  [posix] set default IPv6 hop limit to OPENTHREAD_CONFIG_IP6_HOP_LIMIT_DEFAULT (openthread#5736)
  [net-diag] invoke the callback when failed to get the response (openthread#5653)
  [site] fix border router guide typo in network (openthread#5731)
  [cli] update cli doc (openthread#5729)
  [thread-cert] refactor case 5.1.3 using pktverify (openthread#5708)
  [thread-cert] refactor case 5.1.2 using pktverify (openthread#5686)
  [test] arm build with cmake 3.10 (openthread#5727)
  [clang-tidy] google-readability-casting (openthread#5720)
  [clang-tidy] modernize-use-equals-default (openthread#5719)
  [clang-tidy] readability-avoid-const-params-in-decls (openthread#5717)
  [clang-tidy] modernize-use-equals-delete (openthread#5718)
  [efr32] add MG21/BRD4180B support (openthread#5725)
  [posix] fix cast-align build error on ARM (openthread#5672)
  [logging] add optional `otPlatLogLine()` & use it in NCP/CLI (openthread#5704)
  [clang-tidy] readability-simplify-boolean-expr (openthread#5716)
  [clang-tidy] modernize-use-nullptr (openthread#5715)
  [dataset] add new helper 'SetTlv()' with a template 'ValueType' (openthread#5722)
  [dataset-manager] simplify 'SendSetRequest()' (openthread#5721)
  [nrf528xx] fix SPI issue (openthread#5703)
  [clang-tidy] modernize-use-bool-literals (openthread#5714)
  [cmake] no target_link_options in cmake 3.10 (openthread#5706)
  [low-power] enhance CSL transmission on NRF52840 using `transmit_at` (openthread#5545)
  [build] fix warning of clearing non-trivial type (openthread#5710)
  [scripts] add MLR Backbone multicast routing test (openthread#5578)
  [mlr] fix build when OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE is disabled (openthread#5711)
  [cmake] use init flags in toolchain files (openthread#5705)
  [cmake] set default build type to Debug (openthread#5709)
  [thread-cert] refactor case 5.1.1 using pktverify (openthread#5680)
  [posix] fix udp close (openthread#5690)
Change-Id: Ic7e4051040f093aa6dce9de5e2031a8accddec87
@abtink abtink deleted the type-trait/add-and-use-in-templates branch February 23, 2022 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants