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 条
  • [1] HexType: Efficient Detection of Type Confusion Errors for C plus
    Jeon, Yuseok
    Biswas, Priyam
    Carr, Scott
    Lee, Byoungyoung
    Payer, Mathias
    [J]. CCS'17: PROCEEDINGS OF THE 2017 ACM SIGSAC CONFERENCE ON COMPUTER AND COMMUNICATIONS SECURITY, 2017, : 2373 - 2387
  • [2] Variadic Templates for C plus
    Gregor, Douglas
    Jaervi, Jaakko
    [J]. APPLIED COMPUTING 2007, VOL 1 AND 2, 2007, : 1101 - +
  • [3] Translating Lambda Calculus into C plus plus Templates
    Sefl, Vit
    [J]. TRENDS IN FUNCTIONAL PROGRAMMING (TFP 2021), 2021, 12834 : 95 - 115
  • [4] TCD: Statically Detecting Type Confusion Errors in C plus plus Programs
    Zou, Changwei
    Sui, Yulei
    Yan, Hua
    Xue, Jingling
    [J]. 2019 IEEE 30TH INTERNATIONAL SYMPOSIUM ON SOFTWARE RELIABILITY ENGINEERING (ISSRE), 2019, : 292 - 302
  • [5] Simple and safe SQL queries with C plus plus templates
    Gil, Joseph
    Lenz, Keren
    [J]. SCIENCE OF COMPUTER PROGRAMMING, 2010, 75 (07) : 573 - 595
  • [6] Employing C plus plus Templates in the Design of a Computer Algebra Library
    Brandt, Alexander
    Moir, Robert H. C.
    Maza, Marc Moreno
    [J]. MATHEMATICAL SOFTWARE - ICMS 2020, 2020, 12097 : 342 - 352
  • [7] Automatic Offloading C plus plus Expression Templates to CUDA Enabled GPUs
    Chen, Jie
    Joo, Balint
    Watson, William, III
    Edwards, Robert
    [J]. 2012 IEEE 26TH INTERNATIONAL PARALLEL AND DISTRIBUTED PROCESSING SYMPOSIUM WORKSHOPS & PHD FORUM (IPDPSW), 2012, : 2359 - 2368
  • [8] Neat SIMD Elegant Vectorization in C plus plus by using Specialized Templates
    Gross, Matthias
    [J]. 2016 INTERNATIONAL CONFERENCE ON HIGH PERFORMANCE COMPUTING & SIMULATION (HPCS 2016), 2016, : 848 - 857
  • [9] CASTSAN: Efficient Detection of Polymorphic C plus plus Object Type Confusions with LLVM
    Muntean, Paul
    Wuerl, Sebastian
    Grossklags, Jens
    Eckert, Claudia
    [J]. COMPUTER SECURITY (ESORICS 2018), PT I, 2018, 11098 : 3 - 25
  • [10] INVESTIGATION OF C plus plus VARIADIC TEMPLATES FOR NUMERICAL METHODS AND FINITE DIFFERENCE SCHEMES
    Darian, Hossein Mahmoodi
    [J]. SIAM JOURNAL ON SCIENTIFIC COMPUTING, 2021, 43 (01): : C89 - C125