Early Detection of Type Errors in C plus plus Templates

被引:3
|
作者
Chen, Sheng [1 ]
Erwig, Martin [1 ]
机构
[1] Oregon State Univ, Sch EECS, Corvallis, OR 97331 USA
基金
美国国家科学基金会;
关键词
Metaprogramming; type systems; type reflection; choice types; C plus plus Templates; SAFE;
D O I
10.1145/2543728.2543731
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
Current C++ implementations typecheck templates in two phases: Before instantiation, those parts of the template are checked that do not depend on template parameters, while the checking of the remaining parts is delayed until template instantiation time when the template arguments become available. This approach is problematic because it causes two major usability problems. First, it prevents library developers to provide guarantees about the type correctness for modules involving templates. Second, it can lead, through the incorrect use of template functions, to inscrutable error messages. Moreover, errors are often reported far away from the source of the program fault. To address this problem, we have developed a type system for Garcia's type-reflective calculus that allows a more precise characterization of types and thus a better utilization of type information within template definitions. This type system allows the static detection of many type errors that could previously only be detected after template instantiation. The additional precision and earlier detection time is achieved through the use of so-called "choice types" and corresponding typing rules that support the static reasoning about underspecified template types. The main contribution of this paper is a guarantee of the type safety of C++ templates (general definitions with specializations) since we can show that well-typed templates only generate well-typed object programs.
引用
收藏
页码:133 / 144
页数:12
相关论文
共 50 条
  • [21] A Comprehensive Detection of Memory Corruption Vulnerabilities for C/C plus plus Programs
    Gao, Yuhan
    Chen, Liwei
    Shi, Gang
    Zhang, Fei
    [J]. 2018 IEEE INT CONF ON PARALLEL & DISTRIBUTED PROCESSING WITH APPLICATIONS, UBIQUITOUS COMPUTING & COMMUNICATIONS, BIG DATA & CLOUD COMPUTING, SOCIAL COMPUTING & NETWORKING, SUSTAINABLE COMPUTING & COMMUNICATIONS, 2018, : 354 - 360
  • [22] Interval arithmetic using expression templates, template meta programming and the upcoming C plus plus standard
    Nehmeier, Marco
    [J]. COMPUTING, 2012, 94 (2-4) : 215 - 228
  • [23] DETECTION OF (C plus A)-TYPE DISLOCATION SELF-BLOCKING IN MAGNESIUM
    Grinberg, B. A.
    Ivanov, M. A.
    Antonova, O. V.
    Vlasova, A. M.
    Kruglikov, N. A.
    Plotnikov, A. V.
    [J]. RUSSIAN PHYSICS JOURNAL, 2012, 54 (08) : 906 - 913
  • [24] C plus plus Memory Detection Tool Based on Dynamic Instrumentation
    Fu, Siran
    Cui, Baojiang
    Guo, Tao
    Song, Xuyan
    [J]. ADVANCES IN INTERNET, DATA & WEB TECHNOLOGIES, 2018, 17 : 663 - 674
  • [25] Detection of Memory Leaks in C/C plus plus Code via Machine Learning
    Andrzejak, Artur
    Eichler, Felix
    Ghanavati, Mohammadreza
    [J]. 2017 IEEE 28TH INTERNATIONAL SYMPOSIUM ON SOFTWARE RELIABILITY ENGINEERING WORKSHOPS (ISSREW 2017), 2017, : 252 - 258
  • [26] CoBOT: Static C/C plus plus Bug Detection in the Presence of Incomplete Code
    Gao, Qing
    Zhang, Shikun
    Chen, Xianglong
    Ma, Sen
    Shao, Sihao
    Sui, Yulei
    Zhao, Guoliang
    Ma, Luyao
    Ma, Xiao
    Duan, Fuyao
    Deng, Xiao
    [J]. 2018 IEEE/ACM 26TH INTERNATIONAL CONFERENCE ON PROGRAM COMPREHENSION (ICPC 2018), 2018, : 385 - 388
  • [27] Vulnerability Detection in C/C plus plus Source Code With Graph Representation Learning
    Wu, Yuelong
    Lu, Jintian
    Zhang, Yunyi
    Jin, Shuyuan
    [J]. 2021 IEEE 11TH ANNUAL COMPUTING AND COMMUNICATION WORKSHOP AND CONFERENCE (CCWC), 2021, : 1519 - 1524
  • [28] Static Analysis Approach for Defect Detection in Multithreaded C/C plus plus Programs
    Moiseev, Mikhail
    [J]. SOFTWARE ENGINEERING FOR RESILIENT SYSTEMS, SERENE 2013, 2013, 8166 : 169 - 183
  • [29] EffectiveSan: Type and Memory Error Detection using Dynamically Typed C/C plus
    Duck, Gregory J.
    Yap, Roland H. C.
    [J]. PROCEEDINGS OF THE 39TH ACM SIGPLAN CONFERENCE ON PROGRAMMING LANGUAGE DESIGN AND IMPLEMENTATION, PLDI 2018, 2018, : 181 - 195
  • [30] EffectiveSan: Type and Memory Error Detection using Dynamically Typed C/C plus
    Duck, Gregory J.
    Yap, Roland H. C.
    [J]. ACM SIGPLAN NOTICES, 2018, 53 (04) : 181 - 195