Title: [197643] trunk/Websites/webkit.org
Revision
197643
Author
[email protected]
Date
2016-03-06 14:30:19 -0800 (Sun, 06 Mar 2016)

Log Message

Update style guide to reflect our style of only using "override" or "final" when overriding virtual methods
https://bugs.webkit.org/show_bug.cgi?id=154978

Reviewed by Darin Adler.

* code-style.md:

Modified Paths

Diff

Modified: trunk/Websites/webkit.org/ChangeLog (197642 => 197643)


--- trunk/Websites/webkit.org/ChangeLog	2016-03-06 20:44:49 UTC (rev 197642)
+++ trunk/Websites/webkit.org/ChangeLog	2016-03-06 22:30:19 UTC (rev 197643)
@@ -1,3 +1,12 @@
+2016-03-03  Saam barati  <[email protected]>
+
+        Update style guide to reflect our style of only using "override" or "final" when overriding virtual methods
+        https://bugs.webkit.org/show_bug.cgi?id=154978
+
+        Reviewed by Darin Adler.
+
+        * code-style.md:
+
 2016-02-29  Yusuke Suzuki  <[email protected]>
 
         [DFG][FTL][B3] Support floor and ceil

Modified: trunk/Websites/webkit.org/code-style.md (197642 => 197643)


--- trunk/Websites/webkit.org/code-style.md	2016-03-06 20:44:49 UTC (rev 197642)
+++ trunk/Websites/webkit.org/code-style.md	2016-03-06 22:30:19 UTC (rev 197643)
@@ -1187,4 +1187,74 @@
 
 ```cpp
 drawJpg(); // TODO: Make this code handle jpg in addition to the png support.
-```
\ No newline at end of file
+```
+
+### Overriding Virtual Methods
+
+[](#override-methods) The base level declaration of a virtual method inside a class must be declared with the `virtual` keyword. All subclasses of that class must either specify the `override` keyword when overriding the virtual method or the `final` keyword when overriding the virtual method and requiring that no further subclasses can override it. You never want to annotate a method with more than one of the `virtual`, `override`, or `final` keywords.
+
+###### Right:
+
+```cpp
+class Person {
+public:
+    virtual String description() { ... };
+}
+
+class Student : public Person {
+public:
+    String description() override { ... }; // This is correct because it only contains the "override" keyword to indicate that the method is overridden.
+}
+
+```
+
+```cpp
+class Person {
+public:
+    virtual String description() { ... };
+}
+
+class Student : public Person {
+public:
+    String description() final { ... }; // This is correct because it only contains the "final" keyword to indicate that the method is overridden and that no subclasses of "Student" can override "description".
+}
+
+```
+
+###### Wrong:
+
+```cpp
+class Person {
+public:
+    virtual String description() { ... };
+}
+
+class Student : public Person {
+public:
+    virtual String description() override { ... }; // This is incorrect because it uses both the "virtual" and "override" keywords to indicate that the method is overridden. Instead, it should only use the "override" keyword.
+}
+```
+
+```cpp
+class Person {
+public:
+    virtual String description() { ... };
+}
+
+class Student : public Person {
+public:
+    virtual String description() final { ... }; // This is incorrect because it uses both the "virtual" and "final" keywords to indicate that the method is overridden and final. Instead, it should only use the "final" keyword.
+}
+```
+
+```cpp
+class Person {
+public:
+    virtual String description() { ... };
+}
+
+class Student : public Person {
+public:
+    virtual String description() { ... }; // This is incorrect because it uses the "virtual" keyword to indicate that the method is overridden.
+}
+```
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to