本文介绍了可以SFINAE检测私人访问违例吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想知道如果我测试一个类的成员和成员是私人什么将sfinae响应?

解决方案

是的。



EDIT: C ++ 11 §14.8.2[temp.deduct] 标准报价

这表明 private 可能触发SFINAE错误。阅读:



EDIT结束 / p>

所以在我看来,它会以SFINAE的方式错误,这进一步证实了从Clang摘录:

  // clang / Basic / DiagnosticIDs.h:185-209 

/// \brief枚举描述诊断程序的发射
///在C ++模板参数扣除期间发生时被处理。
枚举SFINAEResponse {
/// \brief诊断不应该报告,但它应该导致
///模板参数扣除失败。
///
///在模板参数
///扣除期间发生的绝大多数错误属于此类别。
SFINAE_SubstitutionFailure,

/// \brief应该完全抑制诊断。
///
///警告通常属于此类别。
SFINAE_Suppress,

/// \brief应报告诊断。
///
///应报告诊断。各种致命错误(例如,
///模板实例化深度超出)属于此类别。
SFINAE_Report,

/// \brief诊断是一个访问控制诊断,将
///在某些上下文中替换失败并在其他上下文中报告。
SFINAE_AccessControl
};

在SFINAE的情况下,访问控制有一些特殊情况。


I wonder whether if i test for some member of a class and the member is private what will sfinae respond? Will it error out hard or will it say ok or will it error out in the sfinae way?

解决方案

Yes.

EDIT: C++11 Standard quote from §14.8.2 [temp.deduct]

This suggests to me that private can trigger an SFINAE error. Reading on:

The "immediate context" is not so clear to me... but it does not contradict my point :)

end of EDIT

So it seems to me that it will error out in an SFINAE way, this is further confirmed by this excerpt from Clang:

// clang/Basic/DiagnosticIDs.h:185-209

  /// \brief Enumeration describing how the the emission of a diagnostic should
  /// be treated when it occurs during C++ template argument deduction.
  enum SFINAEResponse {
    /// \brief The diagnostic should not be reported, but it should cause
    /// template argument deduction to fail.
    ///
    /// The vast majority of errors that occur during template argument
    /// deduction fall into this category.
    SFINAE_SubstitutionFailure,

    /// \brief The diagnostic should be suppressed entirely.
    ///
    /// Warnings generally fall into this category.
    SFINAE_Suppress,

    /// \brief The diagnostic should be reported.
    ///
    /// The diagnostic should be reported. Various fatal errors (e.g.,
    /// template instantiation depth exceeded) fall into this category.
    SFINAE_Report,

    /// \brief The diagnostic is an access-control diagnostic, which will be
    /// substitution failures in some contexts and reported in others.
    SFINAE_AccessControl
  };

There are special cases with regard to Access Control in the case of SFINAE.

这篇关于可以SFINAE检测私人访问违例吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 22:57